Notion - Update from airtable to notion - probleme with relation field

Hi, I’m updating notion from Airtable.
I’m using the HTTP request node as I need to update relation field.
It works well except when multiple relations are involved. I’m having a “ERROR: JSON parameter need to be an valid JSON” error with the following javacript:

“Companies”: {
“relation”: [
{{ $json[“fields”][“NotionId (from Firm)”].map(id => ({ “id”: id })) }}]
}

But the “rendering” looks just fine:

“Companies”: {
“relation”: [
{“id”: “1deb6df5-4c34-49bd-84b0-8d8e289f5327”},{“id”: “0e1813cc-7b24-4a9e-b5cb-2e4953778f89”}]
}

And by the way when I replace the javascript with a static text it works.

Would definitely use some help here. Thank you :pray:

Here is the full JSON body:

{
    "properties": {
        "Name": {
            "title": [
                {
                    "text": {
                        "content": "{{$json.fields.Name}}"
                    }
                }
            ]
        },
        "Notes": {
            "rich_text": [
                {
                    "type": "text",
                    "text": {
                        "content": "{{$json.fields.Notes.replace(/[\r\n"]+/g, "")}}"
                    },
                    "annotations": {
                        "bold": false,
                        "italic": false,
                        "strikethrough": false,
                        "underline": false,
                        "code": false,
                        "color": "default"
                      }
                }
            ]
        },
        "Companies": {
            "relation": [
               {{ $json["fields"]["NotionId (from Firm)"].map(id => ({ "id": id })) }}]
        }
    }
}

Information on your n8n setup

  • n8n version: 1.32.2
  • Database (default: SQLite): SQLite
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker

hello @Rowingbobcat

try this one

"Companies": {
            "relation": {{ $json["fields"]["NotionId (from Firm)"].map(id => ({ "id": id })) }}
        }

Because the map function is an array function and it returns an array.

Thanks @barn4k. I’ve tried what you suggested, but JSON is still not valid:
ERROR: JSON parameter need to be an valid JSON

:frowning:

Any other idea?

Ok I found a solution: I’ve used “Using Fields Below” instead of JSON and use the map function. It works. I can’t explain why it doesn’t work when specifying JSON. The code seems to be exactly the same.

1 Like

Could you kindly share a minimal example of your workflow? I am keen to do the update of relation property via http request as well, while the notion node gets fixed/clarified.

Here you go:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.