SendGrid marketing API workflow

307 Views Asked by At

My app requires ability to subscribe and unsubscribe customers to marketing emails using SendGrid's Contacts API. Customers can also be subscribed\unsubscribed from outside the app so I need to keep track of those as well. I'm currently very confused because most of the actions are asynchronous and I don't see any kind of webhooks for this API either. Basically I don't understand what's the expected workflow when working with this API.

Example A: When I export contacts to catch up on newly subscribed\unsubscribed customers am I expected to just poll the export endpoint until I get the result?

Example B: A customer presses 'Subscribe' and naturally I want an "Unsubscribe" button to appear instead. However I can't do that because I'm still yet to get their contact_id.

Am I missing something or our approach doesn't really work with this API and we need to rethink our strategy?

1

There are 1 best solutions below

0
On

The Contacts API is an asynchronous API as you can send up to 30,000 emails to be added at any one time. When you add a contact via the API, the response includes a job_id which you can then use to query the status of an import job. That is the endpoint you should poll to find out the progress.

Unsubscriptions should not be handled by removing a contact from the list. Instead, you can add email addresses to or delete email addresses from a global suppression list. Or for more granular control over the emails you are sending, you can create unsubscribe groups and then add or remove contacts from those groups.

The API methods to add and delete contacts from suppression groups are synchronous and will allow you to update your UI quicker. However, initially creating a contact is asynchronous and you will have to poll for the job status before you can be satisfied the contact is added.