JavaZero
JavaZero

Reputation: 1

How to use notion API to create tag

I am going to use python to track my wish list of film from the other website. Now I want to give every film some different tags. But notion reference told me

Multi-select property value objects contain an array of multi-select option values within the multi_select property.

So, i want to know how to add tag by notionAPI. or how to create a database with a tag template.

check it

Upvotes: 0

Views: 3476

Answers (3)

iamhite
iamhite

Reputation: 429

For Notion-Version: 2021-08-16', It is able to add Tags in muitl-select form via Notion api.

curl -X POST 'https://api.notion.com/v1/pages' \
  -H 'Authorization: Bearer ''' \
  -H 'Notion-Version: 2021-08-16' \
  -H "Content-Type: application/json" \
  --data '{"parent": { "database_id": "" }, "properties": {"Name": {"title": [{"text": {"content": "Tuscan Kale"} } ] }, "Picture": {"files": [{"name": "000150748673-ofnuhb-t500x500.jpg", "type": "external", "external": {"url": "https://www.yan.sg/blog/wp-content/uploads/2021/11/frc-1c8ef3940bf852e32c300ee2feb9a53b-218x150.jpg"} }] }, "Status": {"multi_select": [{"name": "Rainbow Grocery", "color": "gray"}]}}}'

Upvotes: 0

Snow
Snow

Reputation: 109

Update 06/17:

Select values can now be dynamically created - Notion developers


As far as I know, there's no way to create new select or multi-select option in the current Notion API version (2021-05-13). But the good news is, an unofficial python library can do this.

notion-py is an unofficial Python API client that implements notion operation by simulating the user's http request behavior. When you create or update a page in the database, it can add new options if some of the options in select or multi-select doesn't exist.

Install

Use pip install: pip install git+https://github.com/jamalex/notion-py.git@refs/pull/294/merge

or in requirements.txt file: git+https://github.com/jamalex/notion-py.git@refs/pull/294/merge

About use notion-py to add new options in select or multi-select

Upvotes: -1

D_________
D_________

Reputation: 583

Let's say your tags property is named "Tags":

curl -X POST https://api.notion.com/v1/pages \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -H "Notion-Version: 2021-05-13" \
  --data '{
    "parent": { "database_id": "'${DATABASE_ID}'" },
    "properties": {
      "Name": {
        "title": [
          {
            "text": {
              "content": "'${NAME}'"
            }
          }
        ]
      },
      "Tags": {
        "multi_select": [
          {"name": "'${TAG}'"}
        ]
      }
    }
  }'

Note that you must pre-populate the tag names in your database field prior to adding or you will get the following error:

{"object":"error","status":400,"code":"validation_error","message":"dcp[ is an invalid select option \"TAG NAME\"."

Upvotes: 4

Related Questions