LoginSignup
0
1

More than 1 year has passed since last update.

Notion APIを試す&エラー対応した件

Posted at

はじめに

notion apiを使って、お問い合わせデータベースを作成してみよう!とした時に発生したエラーについて述べます。

Token発行やDatabaseIDの取得は、以下の記事が参考になります。
Qiita

環境

TypeScript
firebase functions

コード

import axios ,{AxiosRequestConfig} from "axios"

const yourDatabaseID = 'あなたのデータベースID
const yourToken = 'あなたのトークン

const options:AxiosRequestConfig = {
      method: "post",
      url:'https://api.notion.com/v1/pages',
      headers: {
        Accept: 'application/json',
        'Notion-Version': '2021-08-16',
        'Content-Type': 'application/json',
        Authorization: 'Bearer ' + yourToken
      },
      data: {
        parent:{
          database_id: yourDatabaseID
        },
        properties: {
          Name: {
            "title": [
              {
                "text": {
                  "content": data.name,
                }
              }
            ]
          },
          },
          "お問い合わせ内容":{
            'rich_text': [
              {
                'type': 'text',
                'text': {
                  'content': data.content
                }
              }
            ]
          },

        }
      }
    };

    return await axios.request( options)

Error

notion message: 'お問い合わせ内容 is not a property that exists.'

解決策

先に、Notion上で、プロパティを作成しておく。
今回は、”お問い合わせ内容”をTextタイプで作成しました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1