Best answer

Need help with Dictionary input fields setup

  • 10 August 2021
  • 2 replies
  • 197 views

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!

icon

Best answer by Zane 10 August 2021, 23:33

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +9

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: