Skip to content

Instantly share code, notes, and snippets.

@crazytonyi
Last active April 19, 2018 19:01
Show Gist options
  • Save crazytonyi/10222135ab7b4d9407d2103130a94cfa to your computer and use it in GitHub Desktop.
Save crazytonyi/10222135ab7b4d9407d2103130a94cfa to your computer and use it in GitHub Desktop.
<?php
$client = new \GuzzleHttp\Client();
$headers = ['x-api-key' => 'MY API KEY'];
$options = [
'headers' => ['x-api-key' => 'MY API KEY'],
'debug' => true,
];
try {
$resp = $client->request('GET', 'https://beta.check-mot.service.gov.uk',$options);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$resp = $e->getResponse();
}
echo $resp->getBody();
@ZalumsArtis
Copy link

This is the output

@crazytonyi
Copy link
Author

The output from what? That looks like it's all command line curl, is that right? If so, it seems like you get a 403 response no matter what. In which case it's not an issue with the code, right?

@ZalumsArtis
Copy link

Thats from command line yes. If I use curl -H "Accept: application/json" -H "x-api-key: your_api_key " \https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=XX10ABC, I get a output and works with any car reg

@crazytonyi
Copy link
Author

Does that also work if you update the URL for the guzzle request?

@ZalumsArtis
Copy link

Would I need to update the actual url within controller?

@crazytonyi
Copy link
Author

The URL in the request.

@ZalumsArtis
Copy link

By using function?

public function apitest(){

$client = new \GuzzleHttp\Client();
$headers = ['x-api-key' => 'Key here'];

$options = [
'headers' => ['x-api-key' => 'Key here'],
'debug' => true,
];
try {
$resp = $client->request('GET', 'https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=XX10ABC
',$options);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$resp = $e->getResponse();
}
echo $resp->getBody();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment