Hide parent objects in the body request (Custom App)

Hi everyone,

I’m currently facing an issue with constructing my body request for a module of a Custom App I am developping. The challenge arises because I need to handle optional parameters and conditionally exclude certain objects from the final JSON payload.

I have two parameters, parameters.images and parameters.event_description, which are optional. Depending on whether these parameters are filled or not, I need to:

  1. Exclude the entire parent object if the parameters are null.
  2. If both parameters are null, exclude the entire content object.

Here’s the current JSON body request I’m working with:

"content": {
        "en": [
          {
            "type": "item",
            "attributes": {
              "assets": "{{parameters.images}}"
            },
            "relationships": {
              "item_type": {
                "data": {
                  "id": "1102482",
                  "type": "item_type"
                }
              }
            }
          },
          {
            "type": "item",
            "attributes": {
              "content": {
                "schema": "dast",
                "document": {
                  "children": [
                    {
                      "children": [
                        {
                          "type": "span",
                          "value": "{{parameters.event_description}}"
                        }
                      ],
                      "type": "paragraph"
                    }
                  ],
                  "type": "root"
                }
              },
              "is_wide": null
            }
        ]
      }

Make.com currently treats null values by “hiding” only the actual object, but I need the entire parent object to be excluded if both parameters.images and parameters.event_description are null otherwise I receive an error. Here is the body request sent by Make when both parameters are null:

"content": {
                "en": [
                    {
                        "type": "item",
                        "attributes": {},
                        "relationships": {
                            "item_type": {
                                "data": {
                                    "id": "1102482",
                                    "type": "item_type"
                                }
                            }
                        }
                    },
                    {
                        "type": "item",
                        "attributes": {
                            "content": {
                                "schema": "dast",
                                "document": {
                                    "type": "root",
                                    "children": [
                                        {
                                            "type": "paragraph"
                                        }
                                    ]
                                }
                            },
                            "is_wide": null
                        },
                        "relationships": {
                            "item_type": {
                                "data": {
                                    "id": "1099719",
                                    "type": "item_type"
                                }
                            }
                        }
                    }
                ]

Notice that only “assets” and “children” were removed from the payload.

Can anyone provide guidance or a snippet on how to construct this JSON object correctly in Make.com? Specifically, how can I ensure the entire content object is excluded if both parameters.images and parameters.event_description are null? Any help or direction to relevant documentation would be greatly appreciated!

Thank you in advance!

Hi @Tiago,

You can make use of IML functions in the Custom App Builder, maybe you can build a solution with the if() function? See: JavaScript in Make | Make Apps

for example, if parameters.images && parameters.event_description are known, then pass the complete object, if not then don’t pass it.

Other than that, I think you must revert to Custom IML functions if you know JavaScript. Although I’d love to be proven wrong on that :slight_smile:

Cheers,
Henk

1 Like

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