How to map attachments from webhook to notion?

Hi,

I’m send data from a form on my website to a webhook one make, works fine.
From this form I can add up to 3 files as attachments.

here is the current scenario :

1 : data received on webhook

2 : iterator to read every file attached on attachments + iterator output

3 : set variable for each file re-build correctly the URL + set variable output

4 : array agregator to build an array with all clean attachments URLs + array agregator output

5 : iterator to make a right array with file_url variable + iterator output

6 : insert database item on notion

but I get this error :

Any idea?

Thanks
L

Hi,
That’s because a File property in Notion expects an array with name and url - see Page properties

So, if you want to map multiple files, you need to setup the correct array before mapping it like you show in the screenshot.
If you are sure you’re always adding only 1 file instead, you can turn off the “Map” toggle in the Make field, and add the name + url directly (mapped from previous modules or manual as needed)

ok thanks I see now.
But how to format correctly the array to match what notion expects?

I have tried to add a CREATE JSON module like this Imgur: The magic of the Internet
But the output looks like this:

[
    {
        "json": "{\"files\":[{\"file_url\":\"https://www.website.com/images/upload_support/cf_68036eac98191_anonymous-wallpaper.jpg\"}"
    }
]

How can I make it looks like this ?

{
  "files": [
    {
      "name": "cf_6805814f424ae_support.txt",
      "external": {
        "url": "https://www.website.com/images/upload_support/cf_6805814f424ae_support.txt"
      }
    }
  ]
}

You can create a data structure that matches the second JSON. In the JSON module, create a data structure from JSON, and copy-paste the JSON from the Notion documentation to generate the data structure

I did but the output provided by Create JSON module looks like this :

[
    {
        "json": "{\"files\":[{\"name\":\"cf_6806a4eb6733a_support.txt\",\"external\":{\"url\":\"https://www.website.com/images/upload_support/cf_6806a4eb6733a_support.txt\"}}]}"
    }
]

Or looks like this also :

[
    {
        "json": "{\"properties\":{\"Blueprint\":{\"files\":[{\"name\":\"cf_6806a4eb6733a_support.txt\",\"external\":{\"url\":\"https://www.website.com/images/upload_support/cf_6806a4eb6733a_support.txt\"}}]}}}"
    }
]

why the JSON output looks like this?

That looks like the raw JSON output - I would try using a “Parse JSON” module right after “Create JSON” to clean up the output, and then map the output of Parse JSON into the Notion module

1 Like

ok thank you I try this