Skip to content

Send function error after upgrade to 4.1.2 #170

Closed
@oaloria

Description

@oaloria

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

Activity

ozanuzer

ozanuzer commented on Apr 8, 2025

@ozanuzer

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

mayocca commented on Apr 8, 2025

@mayocca

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 <matias@yocca.dev>
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

tiwarishubham635 commented on Apr 9, 2025

@tiwarishubham635
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @oaloria@mayocca@ozanuzer@tiwarishubham635

      Issue actions

        Send function error after upgrade to 4.1.2 · Issue #170 · sendgrid/php-http-client