Copyng extant array of values from a GET and appending one more for an HTTP PATCH

How do I do this in Make?

I query a service (e.g. Hubspot via an API module) and an object is returned. From i.e. {{1.body.properties}} - an array of objects - I would like to copy the existing objects, and add one more.

e.g. three existing objects in an arrray with the key: “options”:

{
  "body": {
    ...
    "options": [
      {0...},
      {1...},
      {2...}
    ],
    ...
  }
  "headers": {..}
  "status code": 200
}

… and I would like to transform that into just an object with the three properties plus one more:

{
  "options": [
    {
      "label": "pending",
      "value": "pending",
      "displayOrder": "0",
      "hidden": false
    },
    {
      "label": "active",
      "value": "active",
      "displayOrder": "1",
      "hidden": false
    },
    {
      "label": "other",
      "value": "other",
      "displayOrder": "2",
      "hidden": false
    },
    {
      "label": "test2",
      "value": "test2",
      "displayOrder": "3",
      "hidden": false
    }
  ]
}

I’m at a loss between aggregators and array functions and am realizing I don’t quite understand bundles and collections.

Ultimately I would like to pass the appended array of objects as the body of an API call to e.g. https://api.hubapi.com/crm/v3/properties/deals/user_status?archived=false

Context: essentially I am trying to construct a pattern whereby I can add new (i.e. unrecognized) values for the user_status to a list of options for a single-select “dropdown menu” property in Hubspot.

Thanks :slight_smile:

You can “Create” another “option item” collection quickly with the “Parse JSON” module:

{ "newItem": {
  "label": "new item",
  "value": "value",
  "displayOrder": "3",
  "hidden": false
}}

Then, you can add this item to your options array by using the built-in function add

e.g.:

{{ add(1.body.options; 2.newItem) }}

For more information, see the function documentation in the Help Center.

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

4 Likes

Thank you @samliew - works perfectly!

{{add(1.body.options; 2.one_more_option)}}

where 2.one_more_option is the key for an object matching the extant object structure.

{"one_more_option": {
  "label": "test3",
  "value": "test3",
  "displayOrder": "4",
  "hidden": false}
}
1 Like