Best answer

POST Request to External API with attribute Arrays

  • 20 July 2022
  • 9 replies
  • 1721 views

Userlevel 1

Hello All.

I am trying to create a Zap using WebHooks by Zapier to import contact data from a connected service (in this case Google Contacts) to a CRM using the CRM’s API. According to the guildelines for using the API detailed here (which are fairly standard), I need to use a POST Request with the data for some attributes (email, phone, address, etc.) requiring an array of objects. Here is where I run into trouble. Below is an example of a simple-yet-complete set of data I would hope to convey:


{
"firstName" : "John",
"lastName": "Smith",
"emails":[
{
"type": "Work",
"address": "johnsmith@google.com",
"isPrimary": false
}
]
}

 

I was able to get the full Zap working fine with simple json strings. Namely, I could get the contact info from Google Contacts, field map first/last name, prefix, suffix etc. into the POST Request, and then fire the webhook off to the CRMs API. Sure enough, it would give me a success message and add a new contact with that information into my CRM.

 

After attempting to add the attributes with child attributes however, it would not succeed. I would receive an error from the CRM’s API code 400 and be told to “Please re-map your fields.” After fishing around on support pages, I thought maybe I could use double underscores such as emails__type : “Home” to convey a child attribute, but of course this did not work. I saw that some seemed to have success with adding Code by Zapier elements, but I could not figure this out either. I thought for the longest time I was just formatting everything wrong but when I tried my webhook code with online testing sites the full data set worked fine without hitches and the CRM contact was created. At this point I would’ve moved on from Zapier if another site had all the triggers and sources I needed readily available like they do.

Has anyone else encountered a similar problem? Is it even possible to get Zapier to play nice with arrays and child attributes?

Any help would be appreciated

icon

Best answer by Troy Tessalone 20 July 2022, 22:17

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.

9 replies

Userlevel 7
Badge +14

Hi @dmend18 

Good question.

Please post screenshots with how your Webhook Zap step is configured along with the returned error in order for us to have more context, thanks.

Userlevel 1

Hi @Troy Tessalone 

Here are screenshots of my current attempt at this. I am using Custom Request for POST since the Webhooks by Zapier was not working as configured. Below you can see my setting and sample code. Despite using the same URL, API Key, and data packet itself, it does not seem to work within Zapier. Below also is a screenshot of the POST request succeeding with an online testing site.

 

Userlevel 1

I should note also that I attempted your HTTP Post Request via Zap Code Step detailed here”

 

I did find it well-written and helpful. While it interfaced with the API, I encountered the same oddity where it would work when send from the online testing tool but not from within Zapier.

Thanks,
DGM

Userlevel 7
Badge +14

@dmend18 

Can you provide a screenshot of the returned error when testing in the Zap step?

Do you have your API properly set as part of the POST URL?

You may need to set headers in the Zap step. (check the headers that are set in the other testing tool)

 

Userlevel 1

.@Troy Tessalone 

Here is the screenshot of the returned error.

Best I can figure, my API is properly set within the POST URL. I did not need to set Headers within the testing tool in order for it to operate functionally. Since you suggested it, I did go back and configure the apiKEY as a Header, which returned the same error in the image below.

Userlevel 1

Here is the raw code from the online testing tool.

 

Userlevel 1

See below

Userlevel 7
Badge +14

@dmend18 

Try adding this Header to the Zap step:

 

Userlevel 1

.@Troy Tessalone 

After adding the Content-Type header, the code executes successfully within the Zap. Thank you for your assistance. I will credit your answer and mark the problem resolved.

Dominic