Setting up an add Recipient Using SendGrid API

make

#1

@vinit I was wondering if you could peek at this and determine why I’m getting a 400 error on this API call. I repeated everything from Sendgrid’s “try it out” feature to add a recipient to my contacts list and it works there with my API key, but once I try the exact same set up in the bot I get this error.

I’ve tried a few variations to see if I could get past the error, but haven’t been successful. On the flip side, if I change this from POST to GET, it pulls in my contact list from the SendGrid account just fine. So I know the API authentication and URL are correctly set up.

I would be using JSON that would look like this in the bot (I just used their example for test to remove variables):
[
{
“email”: “{{ursp.email}}”,
“first_name”: “{{ursp.name}}”
}
]

Edit: I deactivated this link. I can set up a test version tomorrow. I was testing a plan B in case this doesn’t pan out. The link to test is https://mvd.hellotars.com/conv/ByStnQ/?_startgid=57


#2

Hi Levi,
It may be the formatting of the code you are using. I tried several versions and modifications from sendgrid docs until I got this one to work:

{
“personalizations”: [
{
“to”: [
{
“email”: "email@gmail.com"
}
],
“subject”: “my subject line”
}
],
“from”: {
“email”: "myemail@gmail.com"
},
“reply_to”: {
“email”: “{{ursp.getcontactemail}}”
},
“content”: [
{
“type”: “text/html”,
“value”: “content of my email with html
etc”
}
]
}


#3

Hi Mark,
Funny story, my ticket submission bot uses that api from SendGrid to send it’s auto-reply with the user’s unique reference code.The previous code you referenced has a duplicate “personalization” in the documentation, which causes the hiccup.

What I’m trying to do is add a receipent to a SendGrid contact list in my account. This will be used to send a single email to subscribers when appointments for REAL ID in Montana will be available. The email will be off of their templated email response. It will include a link directly to the scheduler to set up their appointment, and a link to download a custom document checklist (it also has an automated bot counterpart that can step you through to find out if you have the correct documents or not).

Only problem is the api is not working in the bot. As far as I can tell, everything is configured to SendGrid’s exact specifications on this other api.


#4

Hi Levi,
Oh, got it! That’s a cool setup! Haven’t worked with the sendgrid contact lists yet. Sounds like a great application for what you’re trying to accomplish. I will watch this thread to see how it works out for you, maybe Vinit will have some insights. And yes, noticed some inconsistencies in their docs in places. I’m really loving this sendgrid API integration overall as it’s making the bots even more effective for my applications, and sounds like for you as well. Cheers!


#5

Checking the API docs here:
https://sendgrid.com/docs/API_Reference/Web_API_v3/Marketing_Campaigns/contactdb.html

It looks like the Data Body Format is correct. Certainly no issue with JSON syntax, otherwise the in-gambit editor would cry.

Maybe double check the API token (Authorization Header)

Also, try to make the same API call using POSTMan Client. See if you are facing the same issue. If yes, then something wrong with the Sendgrid API, maybe deprecated. Ping them a message.


#6

I ran it in POSTman and it worked without an issue. I copied everything from the bot into POSTman to keep it consistent. It must be something on the bot’s end. Very strange…


#7

try adding a header field called tarscorsproxy and set it as no.

like this:

25-14-07-21

This skips the CORS proxy in between. Sometimes API behave differently with/without such proxies


#8

I tried this as well, and unfortunately, it did not work.