daninthemix
daninthemix

Reputation: 2570

Accessing specific properties from Guzzle response?

I'm using Guzzle to get an HTTP response. If I do this:

$response = $res->getBody();

I get an object with 'email' as one of the properties. But if I do either:

$email = $res->getBody()->email;

or

$email = $response->email

I get a 'No value for email' error. What am I missing?? How can I access a specific property in the response object?

Upvotes: 3

Views: 2356

Answers (1)

Federkun
Federkun

Reputation: 36924

The getBody method returns an instance of StreamInterface. You first need to retrieve the contents of the response:

$response = (string) $res->getBody();

Only then you can decode the json payload:

$json = json_decode($response); 
$email = $json->email;

Upvotes: 7

Related Questions