Search code examples
javascriptnode.jssendgridsendgrid-api-v3

Sendgrid (Node JS) add contact to custom Marketing list


I'm trying to add a contact to the marketing list with Sendgrid Node JS

 var request = require("request");

      var options = { method: 'PUT',
        url: 'https://api.sendgrid.com/v3/marketing/contacts',
        headers: { authorization: 'Bearer myAPIKEY' },
        body: '{"contacts":[{"email": "myMail@gmail.com","unique_name":"myName"}]}' };

      request(options, function () {
      });

Everything works, but I would also like to add the contact to a specific list. I read the documentation and it says I need to add the id of the contact.

Where can I find that or How can I add a contact to a specific list?

Thank you!


Solution

  • So I read the documentation, you can put a list ID within the body of the request, like this:

    "list_ids":["theidofyourlist"], "contacts" ....