Skip to content

Send function error after upgrade to 4.1.2 #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oaloria opened this issue Apr 7, 2025 · 3 comments · Fixed by #171
Closed

Send function error after upgrade to 4.1.2 #170

oaloria opened this issue Apr 7, 2025 · 3 comments · Fixed by #171

Comments

@oaloria
Copy link

oaloria commented Apr 7, 2025

Hi, I just upgraded from version 4.1.1 to 4.1.2 and noticed that the send function is erroring because of the new type declarations introduced in this version.

Something like this is no longer working.

$sendgrid = new \SendGrid($apiKey);
$email = new Mail(
            new From($this->fromMail, $this->fromName),
            new To($sendTo),
            'Test Email'
        );
$email->addContent('text/plain', 'This is the plain text content of the email.');

$response = $sendgrid->send($email);

The error it shows says:

SendGrid\Client::makeRequest): Argument #3 ($body) must be of type ?array, SendGrid\Mail\Mail given, called in /var/www/html/src/vendor/sendgrid/php-http-client/lib/Client.php on line 662
@ozanuzer
Copy link

ozanuzer commented Apr 8, 2025

I also get the same error. I fixed version to 4.1.1. I will revert back when bug will fixes

p.s "$email->jsonSerialize()" did not fix the error.

@mayocca
Copy link

mayocca commented Apr 8, 2025

Fwiw sendgrid/sendgrid-php#1123 would fix this error but there are a few ones that also surfaced with the new types for Client::makeRequest which are mentioend in sendgrid/sendgrid-php#1124.

Something like this patch should fix the issue from this side until there's a better solution:

From ac2921664ac1ce0e49501c17a71d8da7949c41a5 Mon Sep 17 00:00:00 2001
From: Matias Yocca <[email protected]>
Date: Tue, 8 Apr 2025 15:05:53 -0300
Subject: [PATCH] fix: cast body and query params to array

---
 lib/Client.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Client.php b/lib/Client.php
index 375d059..886bec4 100644
--- a/lib/Client.php
+++ b/lib/Client.php
@@ -645,8 +645,8 @@ class Client
         }
 
         if (\in_array($name, $this->methods, true)) {
-            $body = isset($args[0]) ? $args[0] : null;
-            $queryParams = isset($args[1]) ? $args[1] : null;
+            $body = isset($args[0]) ? (array)$args[0] : null;
+            $queryParams = isset($args[1]) ? (array)$args[1] : null;
             $url = $this->buildUrl($queryParams);
             $headers = isset($args[2]) ? $args[2] : null;
             $retryOnLimit = isset($args[3]) ? $args[3] : $this->retryOnLimit;
-- 
2.48.1

I didn't have a chance to test this yet since it would need to be tested e2e with both packages and the applied patch.

Tagging @twilio-dx since this is currently breaking all new sdk installs.

@tiwarishubham635
Copy link
Contributor

Hi! We are working on this. Will be releasing the fixed version at the earliest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants