You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vercel Edge Runtime调用Notion API返回400 invalid_request_url问题

问题:Vercel Edge Runtime中Next.js API路由调用Notion API返回400错误(invalid_request_url)

现象

在Vercel Edge Runtime的Next.js API路由中调用Notion的Retrieve a database、Query a database接口时,返回400错误,错误信息为invalid_request_url。但在本地环境(next dev、vercel dev)中调用这些接口能正常返回200。

NOTION_API_SECRET与DATABASE_ID已正确配置,预期返回200但未实现。

代码示例

Retrieve a database

import { NextRequest } from 'next/server'

export const config = { runtime: 'edge' }

async function(req: NextRequest) {
  const url = `https://api.notion.com/v1/databases/${DATABASE_ID}`
  const headers = {
      'Authorization': `Bearer ${NOTION_API_SECRET}`,
      'Notion-Version': '2022-06-28',
      'Content-Type': 'application/json',
    }

  const response = await fetch(url, {
    method: 'GET',
    headers: headers,
  })

  const data = await response.json()
  console.log(JSON.stringify(data))
}

Query a database

import { NextRequest } from 'next/server'

export const config = { runtime: 'edge' }

async function(req: NextRequest) {
  const { searchParams } = new URL(req.url);

  if (!searchParams.has('slug')) {
    throw new Error('No slug in searchParams.')
  }

  const slug = searchParams.get('slug').trim()

  const url = `https://api.notion.com/v1/databases/${DATABASE_ID}/query`
  const body = JSON.stringify({
      filter: {
        and: [
          { property: 'Published', checkbox: { equals: true } },
          { property: 'Slug', rich_text: { equals: slug } },
        ],
      },
    })
  const headers = {
      'Authorization': `Bearer ${NOTION_API_SECRET}`,
      'Notion-Version': '2022-06-28',
      'Content-Type': 'application/json',
    }

  const response = await fetch(url, {
    method: 'POST',
    body: body,
    headers: headers,
  })

  const data = await response.json()
  console.log(JSON.stringify(data))
}

已尝试的操作

  • 调用其他公开API可正常响应
  • 尝试将runtime改为experimental-edge,仍返回400错误
  • 本地使用Edge Runtime CLI调用可正常返回200

内容的提问来源于stack exchange,提问作者otoyo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 11:20:25