Trouble setting relation property when creating new Notion database entry via API

I’m having issues with the Notion API while trying to add a new row to a database. The API works fine for title, date, and select properties. But I can’t figure out how to set the relation property correctly.

Here’s what I’ve tried:

{
  "parent": { "database_id": "abc123def456" },
  "properties": {
    "Title": {
      "title": [{ "text": { "content": "My Entry" } }]
    },
    "DueDate": {
      "date": { "start": "2023-10-15" }
    },
    "Category": {
      "select": { "name": "Work" }
    },
    "RelatedCourse": {
      "type": "relation",
      "relation": [{
        "database_id": "xyz789",
        "synced_property_name": "Course"
      }]
    }
  }
}

But I keep getting an error. Any ideas on what I’m doing wrong with the relation property? Thanks for any help!

hey there! i’ve run into this before. for the relation property, you just need the ID of the page you’re linking to, not the whole database_id thing. try something like this instead:

“RelatedCourse”: {
“relation”: [{ “id”: “page_id_here” }]
}

hope that helps! lemme know if you need anything else

I’ve encountered similar issues when working with Notion’s API for relation properties. The key is to provide the specific page ID you want to relate to, rather than the database ID. Here’s what worked for me:

"RelatedCourse": {
  "relation": [{ "id": "specific_page_id_here" }]
}

Make sure you’re using the correct page ID from the related database. Also, double-check that the property name “RelatedCourse” exactly matches what’s in your Notion database. Case sensitivity matters here.

If you’re still encountering errors, it might be helpful to log the full API response. Sometimes Notion provides more detailed error messages that can point you in the right direction. Let me know if you need any further clarification on this.

I’ve dealt with this issue before, and it can be tricky. The problem lies in how you’re structuring the relation property. Instead of including the database_id and synced_property_name, you need to directly reference the specific page ID you want to relate to. Here’s the correct format:

“RelatedCourse”: {
“relation”: [{ “id”: “specific_page_id_here” }]
}

Replace “specific_page_id_here” with the actual ID of the page you’re trying to link. This ID should be from a page within the related database. Also, ensure that “RelatedCourse” matches exactly with your database property name. If you’re still encountering issues, double-check your API authentication and permissions. Let me know if this solves your problem.