1

What is the curl command required to add an email to a sendgrid marketing list? I have looked through the documentation and I am having trouble understanding what the actual curl commands would be because the authorization section and the actual api endpoints are split up. I have tried:

curl -X "POST" "https://api.sendgrid.com/v3/contactdb/recipients" -H "Authorization: Bearer YOURUSERPASSWORDSTRING" -H "Content-Type: application/json" -d '{"list":"Beta List", "email":"bla@bla.com", "name":""}'

It still seems to give me issues even if I add a dummy name and YOURUSERPASSWORDSTRING is determined by calling the following in terminal:

echo -n "user:password\!" | openssl base64

What am I missing? Also, is there a better way to do this using javascript/Meteor.js? Thanks!

Coherent
  • 1,933
  • 5
  • 24
  • 33

1 Answers1

2

cURL supports Basic Auth via the --user or -u flag and will handle the base64 encoding and adding the auth header.

Try

curl -X "POST" "https://api.sendgrid.com/v3/contactdb/recipients" -u username:password -H "Content-Type: application/json" -d '{"list":"Beta List", "email":"bla@bla.com", "name":""}'

And for a bit more info, here's an example from the SendGrid Web API auth docs.

bwest
  • 9,182
  • 3
  • 28
  • 58
  • 1
    Thanks! I found out that this also worked after I created an API key under settings: curl -X "POST" "https://api.sendgrid.com/v3/contactdb/recipients" -H "Authorization: Bearer APICODE" -H "Content-Type: application/json" -d '[{"email":"bla42@bla.com"}]' – Coherent Apr 11 '16 at 15:49
  • 1
    Nice, that's the preferred method. API keys are definitely cleaner – bwest Apr 11 '16 at 15:52
  • @bwest can you look this http://stackoverflow.com/questions/37805193/how-to-add-contact-in-list-using-php-api – Sanjay Nakate Jun 14 '16 at 07:08
  • @Coherent can you post your answer i am not able add contact in list see this question http://stackoverflow.com/questions/37805193/how-to-add-contact-in-list-using-send-grid-php-api – Sanjay Nakate Jun 14 '16 at 12:58