Skip to main content

Hi there,

 

I am trying to setup a Zapier integration with an API that accepts data a certain way. I am using the Dictionary input type to sync custom fields to the API, and this is my current request body: 

body: {
'person': {
'email': bundle.inputData.email,
'sex': bundle.inputData.sex,
'full_name': bundle.inputData.full_name,
...
...
'custom_fields': bundle.inputData.custom_fields
}
}

Which I am assuming results in something like this: 

body: {
'person': {
'email': bundle.inputData.email,
'sex': bundle.inputData.sex,
'full_name': bundle.inputData.full_name,
...
...
'custom_fields': {
"customField1": "custom field 1 value",
"customFiled2": "custom field 2 value"
}
}
}

However, the API that I’m interacting with only accepts custom fields like this: 

body: {
'person': {
'email': bundle.inputData.email,
'sex': bundle.inputData.sex,
'full_name': bundle.inputData.full_name,
...
...
'customField1': 'custom field 1 value',
'customField2': 'custom field 2 value',
}
}

I cannot figure out how to output the dictionary input type in the format that is needed. Any pointers in the right direction or help would be greatly appreciated. Thanks!

One way is to switch to “code mode” (if you’re using the UI tool) and use Object.entries() to lift the entries out and add them to the body object.

Object.assign() would accomplish the same thing, I think.  

Or, I think this may be the easiest and most elegant way, use the spread syntax:

  body: {

    'message': bundle.inputData.message,

    ...bundle.inputData.custom_fields

  }


The spread syntax was exactly what I was looking for. Thanks so much :sweat_smile: