Reputation: 5768
I'm using sendgrid (javascript) to add a new contact to my list. Within marketing.
var request = require("request");
var options = { method: 'PUT',
url: 'https://api.sendgrid.com/v3/contactdb/lists/193029b7-0b8b-4c0c-948d-47d09a157542/recipients',
headers: { authorization: 'Bearer myapi' },
body: '{"contacts":[{"email": "[email protected]","unique_name":"hello"}]}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
But then I get the message 'acces forbidden'.
Am I using the wrong url? (The API token is set to administrator all access.)
Thanks!
Upvotes: 1
Views: 229
Reputation: 4639
It looks like there's a few things going on here.
According to the docs, there are not endpoints in the Contact API that accept the method PUT
.
After checking our own implementation, it also looks like there's an issue with what you're intending to do.
See the docs for adding multiple recipients to a list:
POST https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients HTTP/1.1
Request body:
[
"recipient_id1",
"recipient_id2"
]
In order to use that method, you need to first create the users and retrieve their recipient ID's.
POST https://api.sendgrid.com/v3/contactdb/recipients HTTP/1.1
[
{
"email": "[email protected]",
"unique_name":"hello"
}
]
Check out the links posted for more information on their usage and response.
Upvotes: 1