0

Im calling a vehicle data API at an endpoint and can return the data fine using:

$client = new Client();
$url = "https://uk1.ukvehicledata.co.uk/api/MISC DETAILS;
$result = $client->get($url);

return $result->request;

This is using mock data so the response is:

{
    "Request":{
        "RequestGuid":"",
        "PackageId":""
    "Response":{
        // VEHICLE DATA
    }
}

However, I now wish to store the response in the database but cannot access ->request or ->Request etc.

Using:

return json_encode( (array)$result );

Actually returns the headers from Guzzle and no response data.

Any help?

1 Answer 1

1

You have to convert the body into JSON first:

$jsonArray = json_decode($result->getBody()->getContents(), true);

echo $jsonArray['Request']['RequestGuid'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.