The following response is received when trying to add a numeric custom parameter:
object(SendGrid\Response)[197]
protected 'statusCode' => int 400
protected 'body' => string '{"errors":[{"message":"Bad Request","field":null,"help":null}]}' (length=63)
protected 'headers' => array
0 => string 'HTTP/1.1 400 Bad Request'
1 => string 'Server: nginx'
2 => string 'Date: Tue, 24 Jan 2017 13:29:50 GMT'
3 => string 'Content-Type: application/json'
4 => string 'Content-Length: 63'
5 => string 'Connection: keep-alive'
6 => string 'X-Frame-Options: DENY'
7 => string ''
8 => string ''
JSON encoded request data looks as below:
{
"from": {
"email": "<correct email here>"
},
"personalizations": [
{
"to": [
{
"email": "<correct email here>"
}
],
"custom_args": {
"param": 111
}
}
],
"subject": "Subject",
"content": [
{
"type": "text/html",
"value": "<h1>hello</h1>"
}
]
}
As shown above, json_encode doesn't quotes number properties. Thus 111 is sent as number.
However if the parameter is casted to (string) type, the email is sent successfully.
Personalization::addCustomArg() of the Personalization instance linked to the MailPHP 5.6.29 and 7.0.13
SendGrid 5.1.2
Thanks for taking the time to report this issue @igorokb. I've added this to our backlog so that we will always encode that parameter correctly behind the scenes.
It seems to me to have the same bug, is there a workaround ?
Tried this ($val replaced by $val."" to force to string) without success :
foreach($substitions as $var => $val) {
$personalization->addSubstitution($var, array($val.""));
}
@nelsounet,
Can you please post your payload?
$json_string = json_encode($mail, JSON_PRETTY_PRINT);
echo $json_string;
Thanks!
+1 ran into the same issue
compared to your example code (https://github.com/sendgrid/sendgrid-php/blob/master/USE_CASES.md), this works for me:
$mail->personalization[0]->addSubstitution("{{contractId}}", (string)$someIntegerId);
Same thing started happening for me earlier this year on python...
Ended up changing
mail.add_custom_arg(CustomArg(key=key, value=value))
to
mail.add_custom_arg(CustomArg(key=key, value=str(value)))
to prevent HTTP/1.1 400 Bad Request errors...
This has been moved here.