Ignore Relation If Empty While Updating A Notion Page

I’m updating a relation property in a Notion page, using the Update A Database Item step, with the contents of a map -

Where data is -

CleanShot 2024-01-23 at 09.12.45@2x

I had hoped that if the output of the map was null then that would be ignored but Notion throws an error -

[400] body failed validation: body.properties.With (Type of Person).relation[0].id should be a string, instead was null.

I’ve also tried using an if() to check whether the result of the map was null and not insert anything if it was -

But I get the same error.

I’ve also thought about constructing the body of the request separately but I’m not sure how to create an array of items with a key of id and the value set to the IDs from a map of IDs, for multiple properties, efficiently.

Welcome to the Make community!

1. Screenshots of module fields and filters

Please share screenshots of relevant module fields and filters in question? It would really help other community members to see what you’re looking at.

You can upload images here using the Upload icon in the text editor:
Screenshot_2023-10-07_111039

2. Scenario blueprint

Please export the scenario blueprint file to allow others to view the mappings and settings. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826
(Note: Exporting your scenario will not include private information or keys to your connections)

Uploading it here will look like this:

blueprint.json (12.34 KB)

3. And most importantly, Output bundles

Please provide the output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

A.

Save the bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading it here will look like this:

bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

2 Likes

Hey Sam, there’s lots of screenshots in my post, just let me know if there’s anything else you need to see :raised_hands:

Here’s a simple blueprint which you can use to replicate the issue blueprint (15).json (38.8 KB), using this Notion template.

Hello @alexs .
You have to put a filter between the JSON & Notion Module & put condition in filter i.e. Check for (Name Exists or not)

3 Likes

Thanks but I still need to update the page, to populate other properties, even if the Type is empty.

I’m updating quite a few relation properties here so using routers with filters would get very messy. There must be a way to either insert an empty value that Notion will accept or not include the property in the request when sending the request

@alexs Did you try with empty string?

3 Likes

Yes, I still get the same error.

Screenshot 2024-01-23 151833
@alexs
Try using this Formula,
If this formula doesn’t work, replace “ignore” with “N/A” because Notion doesn’t allow to update an empty string

3 Likes

Thanks but neither of those options work, if you mean just entering N/A as text as the fallback?

I’ve even just tried fetching the page and populating the property with the current contents of the property if the result of the map is null (which is just []) and that doesn’t work.

There seems to be an issue with the way that the output of the map is being evaluated because if I set a valid page ID as the fallback for isempty() or if() then I still get the error. But if I set the page ID as the value for the property, without any logic, it’s accepted :thinking:

I’ve tried the if() = test with null, emptyarray, emptystring and no additional criteria.

length(map(1.data; "Type")) gives me an output of 1, even though the result is null so that’s good :upside_down_face:

This is the result of the map:

[
    {
        "Type": [
            null
        ]
    }
]

Ok so the issue was with the test, not with the output:

map(1.data; "Type")) = null is false

but first(map(1.data; "Type")) = null is true.

So I can use that as the test and then:

if(first(map(1.data; "Type")) = null; ; map(1.data; "Type")) works.

2 Likes

Hi @alexs :wave:

I just want to quickly step in to say awesome work figuring this one out with the pointers from @samliew and @sachinkadam5 :clap:

Thanks a lot for keeping us posted on your progress and for sharing what ended up doing the final trick. :pray:

2 Likes