I am trying to use the sendgrid V3 api to add our users to a mailing list. I have constructed the following Ajax request to hit their API, but I keep getting a bad request
error. I omitted xhr.setRequestHeader
, but I do have a valid API key and it works, because when it is omitted, it returns a 403. Now, I just get 400 for bad request body. I have made my request body look EXACTLY like their example and am still stuck.
var sendgridData =
[
{
"marketing_emails": 0,
"weekly_emails": 0,
"email": userProfile.email,
"first_name": "foo",
"last_name": 'bar',
"userid": 2,
}
]
$.ajax({
method: 'POST',
url: 'https://api.sendgrid.com/v3/contactdb/recipients',
data: sendgridData,
dataType: 'json',
contentType: 'application/json',
},
success:
function(res)
{
console.log(1, res)
Modal.close();
},
error:
function(e)
{
Modal.close();
console.log(1,e);
}
})