Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API: Relation Property

Tags:

notion-api

API: Relation Property

Good

I am sending information to a Notion table. The problem I have is with a relation property.

I have tried passing name, passing id, but I can't find the correct call. Does anyone have an example or a link where they report on how to use them. When doing a query the field returns empty, so it doesn't work as an example.

Example:

{
  "parent": {
    "type": "database_id",
    "database_id": "538dfa97-b0f3-4df6-8388-9dbd16f50ad7"
  },
  "properties": {
    "Nombre Tarea": {
      "title": [
        {
          "type": "text",
          "text": { "content": "TAREAS 1" }
        }
      ]
    },
    "Asignado": { "multi_select": [ { "name": "" } ] },
    "Origen": { "select": { "name": "Trabajo" } },
    "Cliente": { "relation": { "name": "CLM" } }
  }
}

or change 

  "Cliente": { "relation": [{ "id":"Usal-2b240920b9554e869b0a49b30d433cef"   } ]}

The answers are:

{
    "object": "error",
    "status": 400,
    "code": "validation_error",
    "message": "Cliente has a value that does not match its property type: relation."
}

{
    "object": "error",
    "status": 400,
    "code": "validation_error",
    "message": "Cliente has a value that does not match its property type: relation."
}


like image 549
David Palazon Avatar asked Apr 29 '26 15:04

David Palazon


2 Answers

Have you shared the database you are relating to with the integration? Any references to other databases or pages that have not been shared with the integration will not be accessible.

A call like this one below will create a page with a relation to a given database as long as that one is also shared with the integration. Make sure that your relation column is only 1 level deep. If the column you are calling in the relation table relies on other tables, it may not work at this time. So, avoid nested tables if possible for relations and roll-ups.

curl --location --request POST 'https://api.notion.com/v1/pages' \
--header 'Content-Type: application/json' \
--header 'Notion-Version: 2021-05-13' \
--header 'Authorization: Bearer YOUR_BOT_TOKEN' \
--data-raw '{
   "parent":{
      "database_id":"YOUR_DATABASE_ID"
   },
   "properties":{
      "YOUR_PAGE_NAME_COLUMN":{
         "title":[
            {
               "text":{
                  "content":"TestPage"
               }
            }
         ]
      },
      "YOUR_RELATION_COLUMN_NAME":{
         "relation":[
            {
               "id":"YOUR_RELATION_PAGE_ID"
            }
         ]
      }
   }
}'
like image 67
adlopez15 Avatar answered May 04 '26 00:05

adlopez15


Take a look at this similar question

Notion - Querying databases and pages provide limited properties

You have to give the same read permissions to the app you are creating for the database that you are trying to point the relation property to. Otherwise, it will not know it exists and therefore it thinks that the relation ID that you are providing does not exist.

You will also need to confirm that the ID exists in the other database which I assume you have done since you already have the ID listed in your example code.

like image 21
Spectrem Avatar answered May 03 '26 22:05

Spectrem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!