2

Will someone help me with the PHP code to authenticate my Sendgrid account connection and then delete a Marketing Campaign recipient via API?

From the help documentation, this appears to be the command line -- DELETE https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients/{recipient_id} HTTP/1.1 -- but I can't figure out what to do with it, since it isn't regular PHP code. The only sample code I found pertained to Legacy Newletters (which I got to work) and not contacts used by Marketing Campaigns.

RSThomas
  • 21
  • 2

1 Answers1

1

What are you using to interact with the API? cURL? You just need to make an HTTP DELETE request to the url https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients/{recipient_id}, replacing {list_id} and {recipient_id} with the IDs of the list and the recipient.

Here's an example of a function that will make a delete request for you with cURL: https://stackoverflow.com/a/17935536/401096

Community
  • 1
  • 1
bwest
  • 8,098
  • 3
  • 23
  • 54
  • Thank you! This is what I have come up with so far (too long to post as an answer): http://rstunlimited.us/API-PHP-DeleteRecipient.html – RSThomas Jan 24 '17 at 14:39
  • Yes, you need the recipient ID, not the email address. It's returned upon creation of the recipient. You can also see it by iterating through your recipients https://sendgrid.com/docs/API_Reference/Web_API_v3/Marketing_Campaigns/contactdb.html#List-Recipients-GET. You can also see it in the URL if you look at your Recipients via the UI, e.g. `https://sendgrid.com/marketing_campaigns/ui/recipients/{recipient_id}`. Your DELETE request should not have a body payload. – bwest Jan 25 '17 at 18:05
  • This is what I am trying to do: For internal purposes, I want to embed an unsubscribe link in the message that when clicked will run a PHP/cURL script to remove the recipient from my SendGrid Contacts list, as well as perform a certain task on my server. API is the only method I see to do this on SendGrid, but I need to be able to pass the recipient_id automatically to the unsubscribe link -- for example like I can do with the email address [%email%]. So how can I get it from the database of contacts as the message is sent to each recipient? (continued) – RSThomas Jan 26 '17 at 21:29
  • 4
    When I view a contact record I see the email address and first and last name, but no recipient_id field. And there is no recipient_id field in the Tags list of the Campaign editor. Bottom-line question: Is the recipient_id even available for me to use the way I am asking? – RSThomas Jan 26 '17 at 21:29