mailjet / mailjet-apiv3-php

[API v3] Mailjet PHP Wrapper
http://dev.mailjet.com
MIT License
267 stars 86 forks source link

Response.php decodeBody error with Guzzle and PSR7 #216

Closed ValCanBuild closed 3 years ago

ValCanBuild commented 3 years ago

Whenever I try to do any API call I get a json_decode error in Response.php

It's because of the decodeBody line here

public function __construct($request, $response)
    {
        $this->request = $request;

        if ($response) {
            $this->rawResponse = $response;
            $this->status = $response->getStatusCode();
            $this->body = $this->decodeBody($response->getBody());
            $this->success = floor($this->status / 100) === 2 ? true : false;
        }
    }

$response->getBody() here is a GuzzleHttp\Psr7\Stream and the decodeBody function passes it straight into json_decode which expects a string instead. This reuslts in a json_decode() expects parameter 1 to be string, object given error.

I'm using the latest version of the https://github.com/mailjet/laravel-mailjet library which I assume is using the latest version of this one. Are my settings wrong or does the library just need a string cast?

uavn commented 3 years ago

Fixed in v1.5.1 https://github.com/mailjet/mailjet-apiv3-php/commit/7b94fa629d46fa5ba3826ed4596674942944520d

You need to update your composer deps

ValCanBuild commented 3 years ago

@uavn I use the laravel-mailjet plugin - anychance that can get updated to use this version as well?

uavn commented 3 years ago

@ValCanBuild just update your laravel composer dependencies, it will download 1.5.1:

root@0181498cd37a:/var/www/mailjet/laravel-mailjet# php composer.phar up
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 30 updates, 0 removals
  - Upgrading fzaninotto/faker (v1.9.1 => v1.9.2)
  - Upgrading mailjet/mailjet-apiv3-php (v1.5.0 => v1.5.1)