super.t
super.t

Reputation: 2736

SendGrid v3 400 bad request

I'm using sendgrid/sendgrid-php the repo on github to send transnational emails. Today I've updated the library, the new one uses the API v3 whereas I used v2 before. I've changed the code as per their examples, here is a dump of my SendGrid\Mail object:

enter image description here

The problem is that I'm constantly receiving the 400 BAD REQUEST error without any additional info:

enter image description here

What am I doing wrong? The mail object seems to be correct.

I'm trying to send the email the following way:

$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$request_body = [creating the mail object];
$response = $sg->client->mail()->send()->post($request_body);

Upvotes: 0

Views: 2680

Answers (1)

Jeremy Hamm
Jeremy Hamm

Reputation: 499

I was having the same issue and discovered all personalizations need to be strings with double quotes. In your example:

$md_email_id = (string)26921

More info https://github.com/sendgrid/sendgrid-php/issues/264

Upvotes: 1

Related Questions