Skip to content

SendGrid\\Client::makeRequest(): Argument #3 ($body) must be of type ?array, SendGrid\\Mail\\Mail give #1124

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
AdamDomafoldi opened this issue Apr 8, 2025 · 18 comments

Comments

@AdamDomafoldi
Copy link

AdamDomafoldi commented Apr 8, 2025

PHP 8.4

SendGrid 8.1.11

I get this error message when sending an email:

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

My code:


 $fromEmail = "info@example.com";
        $fromName = "Example Solutions";

        $email = new Mail();
        $email->setFrom($fromEmail, $fromName);
        $email->addTo($Email, $Name);
        $email->setSubject("Subject");
        $email->addContent("text/plain", "Find attached the spec sheet.");
        $email->addContent(
            "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
        );

        
        $sendGrid = new \SendGrid($_ENV['SENDGRID_API_KEY']);

        $sendGridResponse = $sendGrid->send($email);
        if ($sendGridResponse->statusCode() === 202) {
         
        } else {
            throw new Exception("Caught exception: " . $sendGridResponse->body());
        }
@DanRyan483
Copy link

Can confirm. I am receiving the same error response when attempting to send messages. This was working on previous releases. Full error message below.

SendGrid\Client::makeRequest(): Argument #3 ($body) must be of type ?array, SendGrid\Mail\Mail given, called in /app/vendor/sendgrid/php-http-client/lib/Client.php on line 662

@DanRyan483
Copy link

The error appears to be resulting from line 511 in SendGrid\Client::makeRequest()

public function makeRequest($method, $url, ?array $body = null, ?array $headers = null, $retryOnLimit = false)

probably should be:

public function makeRequest($method, $url, \SendGrid\Mail\Mail|array|null $body = null, ?array $headers = null, $retryOnLimit = false)

Note: the docblock above it is outdated as well on line 503

@DanRyan483
Copy link

DanRyan483 commented Apr 8, 2025

After digging through https://github.com/sendgrid/php-http-client repo, it appears this should be handled over there since the affected code is not in this repo: sendgrid/php-http-client#170.

@AdamDomafoldi
Copy link
Author

@DanRyan483 It has been broken at least since 8.1.9, I am trying to go back to the last working version.

@chrisShick
Copy link

I am getting this issue when we updated our dependencies today. However, our productions are still working on 8.1.2

@chrisShick
Copy link

However, when updating our local environments back down to 8.1.2, it still throws this error

@chrisShick
Copy link

Does this #1123 fix the issue?

@DanRyan483
Copy link

DanRyan483 commented Apr 8, 2025

I haven't had the chance to check #1123. For now, I have temporarily forced sendgrid/php-http-client to 4.1.1 via composer on my repo to get around the issue until it gets patched.

composer require sendgrid/php-http-client "4.1.1"

From what I can tell, the issue is just a declaration problem in the makeRequest() method (see my previous notes). After rolling back to 4.1.1 everything appears to be working as expected.

Edit: just for refererence, I'm pretty sure this issue was triggered by the following commit (see line 511): sendgrid/php-http-client@c859858

@jcperuffo
Copy link

Facing this problem here (PHP 8.1) - SendGrid version 8.1.2 up to 8.1.11 give the same error. Using 8.1.1 here works as before.

@mdasiff
Copy link

mdasiff commented Apr 9, 2025

I'm getting same error since yesterday.

"php": "^7.3|^8.0",
"laravel/framework": "^8.65",
"sendgrid/sendgrid": "^8.1",

TypeError
SendGrid\Client::makeRequest(): Argument #3 ($body) must be of type ?array, SendGrid\Mail\Mail given, called in /home/forge/landkhoj.com/vendor/sendgrid/php-http-client/lib/Client.php on line 662

@tiwarishubham635
Copy link
Contributor

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

@tiwarishubham635
Copy link
Contributor

I have raised a PR to fix this. Will get this merged and release the new version of php-http-client that should solve this issue. Thanks!

@abdulkader-freij
Copy link

I think you can update the send function in this package and serialize the email if u want to keep the type in the other package:
/**
* Make an API request.
*
* @param Mail $email A Mail object, containing the request object
*
* @return Response
*/
public function send(Mail $email)
{
return $this->client->mail()->send()->post($email->jsonSerialize());
}

@tiwarishubham635
Copy link
Contributor

I think we would like to figure out better ways to get the deprecation out as well as not breaking anything. So, will create a separate PR for new changes

@cjhewett
Copy link

cjhewett commented Apr 9, 2025

For those still mentioning their version of sendgrid/sendgrid, this is not the package which is actually causing the issue.

The workaround is specifically adding "sendgrid/php-http-client": "4.1.1" to the require section of composer.json, just make sure to remove it in a week or so when SendGrid has pushed the fix.

Its nice to see the SendGrid PHP libraries getting some much needed work, but its concerning such a serious breaking bug got through and had to be reported by end users.

@mdasiff
Copy link

mdasiff commented Apr 11, 2025

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

is it resolved?

@AdamDomafoldi
Copy link
Author

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

is it resolved?

It seems that the pull request has not been approved yet: #1123

@tiwarishubham635
Copy link
Contributor

Hi! We have released the fixed version of php-http-client. Please check now and let me know if there are still any issues. Thanks!

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

No branches or pull requests

8 participants