0

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."
}


  • I suggest adding exactly what you are trying to do/achieve with your API call. That will make it easier for others to help you. As well, I suggest changing the title of your post to be more specific to your question. – Spectrem Aug 05 '21 at 03:53
  • The specific issue with your code sample is that your `relation` is an object when the API expects an Array and that you need to reference the id of the relation not the name. `"Cliente": { "relation": { "name": "CLM" } }` should actually be `"Cliente": { "relation": [{ "id": "CLM" }] }` – stwilz Aug 04 '22 at 11:10

2 Answers2

5

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"
            }
         ]
      }
   }
}'
adlopez15
  • 3,449
  • 2
  • 14
  • 19
1

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.

Spectrem
  • 682
  • 1
  • 11
  • 37