-
-
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(); |
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?
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
Does that also work if you update the URL for the guzzle request?
Would I need to update the actual url within controller?
The URL in the request.
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();
}
This is the output