Question

Sendgrid Webhook: Adding Contacts to Specific Lists

  • 17 May 2023
  • 9 replies
  • 261 views

Hi guys-

 

Found some helpful topics here on the community pages about using webhooks to add contacts to Sendgrid. Great stuff, but I’ve hit a wall and not sure what to do.

 

I am trying to add contacts to a specific list, not just my general/global contact list. Below is the JSON code I’ve used. What’s odd is that when I did a test of this within Zapier it worked perfectly. However, now that it’s live, the contacts only get added to my global list and then I manually have to add them to the specific list which is not an option given the automations that need to happen after being added to that particular list. 

 

{ "contacts": [{ "email": "emailaddress”, "first_name": "name”, "last_name": "name", "list_id": "listid" }]}

 

To confirm, I am confident that the list id # that I am using is correct for my intended contact list.

 

Any help would be greatly appreciated!


9 replies

Userlevel 7
Badge +12

Hi @andrewoh!

Hmm, it’s odd that this would work in a test but not when the Zap is live. Is the list ID populated from a previous step in the Zap or is it ‘hard-coded’ (ie you’ve typed it in and it’s the same list every time). 

 

One thing to take a look at is the Zap history. Open a successful Zap run and look at the data in and data out for the webhooks step to see if there’s any information that Sendgrid returns around which list the contact has been added to. As it’s a webhook step, there might not be much information there (eg it could just be a 200 success code). If you can’t find anything there, I’d recommend reaching out to the Support team on this one as they can take a look at the Zap logs to see if SendGrid returns any additional information that might help to understand the issue. 

You could also ask SendGrid support if they can take a look at the data coming in to see if they can identify why it wasn’t added to the correct list. 

 

​I hope that helps!

Hi Danvers- Appreciate the quick response.

 

1- Yes, the list ID is hard-coded in.

2- The ‘data-out’ is very minimal as you thought may be the case.. all it shows is: “job_id: 2acec5d6-cf65-4a91-80f1-fd3a5d816a1d”

 

I had asked Zapier support but they couldn’t provide anything useful and suggested I reach out here instead.. But I’ll try SendGrid too!

 

Andrew

Welp- just checked with Sendgrid and they are refusing to help as well..

I figured this out!

https://support.leadbyte.co.uk/hc/en-us/articles/4936296589329-Adding-contact-to-a-list-in-SendGrid

Found this article here which helped with the structure of the json:

{"contacts": [{"email": "[email]"}],"list_ids": ["ABC123-9876-1234-ABCD-ab12cd56ef78"]}

 

The list ID can be found at the end of the list url.

 

I ended up with a very long JSON like this:

{
"contacts": [
{
"email": "emailaddress", "first_name": "firstname", "last_name": "lastname", "custom_fields": {"w5_T": "company", "e21_T": "leadsourcename", "e22_T": "leadlocationname", "e16_T": "campaignname", "e17_T": "campaignsource","e18_T": "campaignmedium","e19_T": "campaignterm","e20_T": "campaigncontent"}
}
],
"list_ids": [
"4655a797-f121-4976-88e7-8b4943886549"
]
}

 

You can get the IDs of your custom fields by following these steps:
https://docs.sendgrid.com/api-reference/custom-fields/get-all-field-definitions

Run it through here: https://reqbin.com/curl

Userlevel 1

@aneubauer I’m trying to do the exact same thing, but I’m getting an error, can you take a look what I’m doing wrong?

 

 

With this I’m currently getting this error:

 

And this is the resulting Json output:

Your help would be very much appreciated.

Hi @Tools !

I used a different type for my Webhook:

 

And then under Action:

I hope this is the answer to your problem.

 

Also, I don’t think you need the brackets around the dynamic email field from your Google sheet.
 

Let me know if you get it to work!

Userlevel 1

It worked! You are my hero @aneubauer !

So I had to change to custom webhook and you were right, no parenthesis needed for the email field.

Thank you!!!

Hooray!! So glad it worked for you!

Hi - I am trying this exact thing, but I get an error message:

{"errors":[{"field":null,"message":"authorization required"}]}
did you previously set up API keys on sendgrid or provide any other access for this to work?
thanks in advance for any advise!

Reply