Thursday, March 2, 2017

[ANSWERED]Can't access Guzzle request properties - Laravel

I'm making a guzzle request that gives me the following response:
{
  "success": false,
  "errors": {
  "customer_id": "Crédit insuffisant sur le compte client"
}

PRINT_R of $request:
GuzzleHttp\Psr7\Response Object ( [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK [statusCode:GuzzleHttp\Psr7\Response:private] => 200 [headers:GuzzleHttp\Psr7\Response:private] => Array ( [Date] => Array ( [0] => Thu, 02 Mar 2017 22:02:02 GMT ) [Content-Type] => Array ( [0] => application/json ) [Content-Length] => Array ( [0] => 89 ) [Connection] => Array ( [0] => keep-alive ) [Server] => Array ( [0] => Apache/2.4.18 (Ubuntu) ) [Set-Cookie] => Array ( [0] => PHPSESSID=qhtpgvd5mhqg1a7gctpagvhap2; path=/ ) [Expires] => Array ( [0] => Thu, 19 Nov 1981 08:52:00 GMT ) [Cache-Control] => Array ( [0] => no-store, no-cache, must-revalidate ) [Pragma] => Array ( [0] => no-cache ) ) [headerNames:GuzzleHttp\Psr7\Response:private] => Array ( [date] => Date [content-type] => Content-Type [content-length] => Content-Length [connection] => Connection [server] => Server [set-cookie] => Set-Cookie [expires] => Expires [cache-control] => Cache-Control [pragma] => Pragma ) [protocol:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #339 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( ) ) )

I want to be able to access "success" but ...
if I do json_decode($request->getBody()):
The Response content must be a string or object implementing __toString(), "object" given.

If I do $request->success:
Undefined property: GuzzleHttp\Psr7\Response::$success



via Bruno Teixeira

Advertisement