Search code examples
zapier

Why doesn't my Zapier Integration Dynamic Field work?


I have a simple zapier integration built and it works perfectly. However, I'm adding dynamic fields. Again it all seems to work perfectly when I test the zap. My dynamic form fields appear just as I expected.

The problem is sending the value of those dynamic forms to my API. I am using the zapier console and when I configure the API request I am using the following:

Where body['custom_fields'] is supposed to send all my dynamic fields or even all of the fields. But when it hits my API custom_fields parameter is blank.

const options = {
  url: 'https://example_url/endpoint',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.auth_token}`
  },
  body: {
    'email': bundle.inputData.email,
    'custom_fields': bundle.inputData

    /**
      I've tried the following with no luck:

     'custom_fields': bundle.inputData.fields
     'custom_fields': bundle.inputData.undefined
     'custom_fields': bundle.inputData
    */
  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });

Solution

  • Ok after a few days, it's the simplest answer.

    Obviously an object can't be sent over params.

    so instead of having

    'custom_fields': bundle.inputData
    

    I just add the whole object to the params and it takes care of all keys and values

    params: bundle.inputData
    

    Here is the full body

    const options = {
      url: 'https://apiendpoint.com',
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${bundle.authData.auth_token}`
      },
      params: bundle.inputData,
    
    }
    
    return z.request(options)
      .then((response) => {
        response.throwForStatus();
        const results = response.json;
    
        // You can do any parsing you need for results here before returning them
    
        return results;
      });