API Connector: Sendgrid API Not Working as Expected

Hey Bubblers!

Having an issue with using the API Connector to interact with the SendGrid API to send dynamic email content using a SendGrid template.

Problem:

When using the API Connector to send dynamic emails, the email gets sent and the correct (202) response is received, but the dynamic data is not populated in the email.

What I’m trying to do:

I’m wanting to use the API Connector (and NOT the plugin), because none of the plugins cater for two fields which are available in the API which I want to use, but none of the plugins have inputs for, namely:

  • custom_args and
  • categories

However, when I setup the SendGrid API in the API Connector using the V3 API docs from here, the actual email that gets sent is not correct.

Things I’ve tried:

  1. I’ve tried using the same credentials with the CoPilot SendGrid plugin. This obviously omits the two fields I want added. The email is sent correctly and the dynamic content populates. All good.

  2. I’ve tried using the Make.com SendGrid integration to send the email. Works fine. Although I did note that when inspecting the API request that Make sends, it’s of a very different format than the API docs that are stipulated in the link above (and it is using the most up to date - V3 - API version). Maybe that’s just the way the integration has been setup.

  3. I’ve tried stripping down the request in the API connector only the required fields from the API. Still, no dynamic content is pulled through (not even the subject field).

  4. I’ve tried moving the custom_args value out of the main request data object and nested it inside the personalizations array. Didn’t work.

What I thought might work:

  • Trying to intercept the API call from CoPilot SendGrid’s Plugin request and copying the curl of that request and modifying it to include the two values I want. I can’t seem to actually isolate that request though using Developer Tools.
  • Trying to inspect the source code of the CoPilot plugin to see if I can find the request body and structure in the code somewhere. No luck in finding that.

Any help much appreciated.

Screenshot what your calls look like right now, and by any chance does your body content have any quotes or other symbols that could break the JSON formatting?

1 Like

Any reason you are using Sendgrid rather than something like Postmark?

Client choice, not mine, unfortunately.

1 Like

At the enpoint level, the only shared header is the Auth header so won’t share that.

Here’s the setup:

And then here’s the redacted data:

 {
"personalizations":[
	{
		"to":{
				"email":"<emailTo>",
                "name":"<nameTo>"
			}
	}
],
"from": {
        "name": "Redacted",
        "email": "Redacted"
    },

"send_to": [
        {
            "name": "<To Name>",
            "email": "<To Email>"
        }
    ],
"subject": "<Subject>",
                    
"reply_to": {
        "email":"redacted"
},
                    
"custom_args": [
        {
            "newsletter-send-id":"<newsletter send id>"
        }
],
                    
"content":{
	"type":"text/html",
    "value":"1"                
},
                    
"categories": [
	"newsletter"
],         

"dynamic_template_data": {
    "preheader": "<preheader>",
    "mainimgurl": "<mainimg>",
    "mainimgalt": "<mainimgalt>",
    "col1row1heading": "<heading1>",
    "col1row1img": "<img1>",
    "col1row1url": "<url1>",
    "col1row1button": "<button1>",
    "col1row1sub": "<sub1>",
    "col2row1heading": "<heading2>",
    "col2row1img": "<img2>",
    "col2row1url": "<url2>",
    "col2row1button": "<button2>",
    "col2row1sub": "<sub2>",
    "col1row2heading": "<heading3>",
    "col1row2img": "<img3>",
    "col1row2url": "<url3>",
    "col1row2button": "<button3>",
    "col1row2sub": "<sub3>",
    "col2row2heading": "<heading4>",
    "col2row2img": "<img4>",
    "col2row2url": "<url4>",
    "col2row2button": "<button4>",
    "col2row2sub": "<sub4>"
  },
                        
  "template_id": "<templateID>",
                        
  "send_at": <sendAtUnix>,
                      
  "tracking_settings": {
    "click_tracking": {
      "enable": true,
      "enable_text": false
    },
    "open_tracking": {
      "enable": true
    },
    "subscription_tracking": {
      "enable": false
    }
  }
}

Annoying!

Does it work if you just use a simpler body? I tried just sending an email with a dynamic body set and it sent ok.

What I think is that you may have empty value, but send it as string “” instead of null.
The best is to inspect your code using step by step and also, instead of sending the request to sendgrid, send it to requestbin to inspect the payload sent by bubble. (you can also do it from API Connector where you get 202 response so you can compare both payload from API Connector and from frontend).

1 Like

No, unfortunately not.

I stripped the request down to only the required fields and even still the subject field doesn’t populate.

Were you able to solve it? I’m having a similar problem. The API connector says that the API call returned an empty body whereas it is not empty. I verified the API key and the body using postman and it is working fine but for some reason, it is not working with the connector.

1 Like

I am getting that today. Did you solve yours?

this happened to me a while ago, I thought it was all this crazy stuff, but it was literally just quotes and symbols

@stephanie4 have you checked closely for this?

@simonpurdon10 I spent a long time on this integration, but I was able to figure it out just through the API Connector and now it’s great since I don’t have to use any third parties

1 Like

Yeah, I looked at every single character. I set it aside to work on another project for awhile. Thanks!

1 Like

My pleasure :slight_smile: