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();
@crazytonyi
Copy link
Author

That's using a valid API key for both?

@ZalumsArtis
Copy link

Oh no just noticed

@ZalumsArtis
Copy link

  • Rebuilt URL to: https://beta.check-mot.service.gov.uk/
  • Trying 161.112.232.221...
  • Connected to wwwproxy.hud.ac.uk (161.112.232.221) port 3128 (#0)
  • Establish HTTP proxy tunnel to beta.check-mot.service.gov.uk:443

CONNECT beta.check-mot.service.gov.uk:443 HTTP/1.1
Host: beta.check-mot.service.gov.uk:443
User-Agent: curl/7.47.0
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
<

  • Proxy replied OK to CONNECT request
  • found 173 certificates in /etc/ssl/certs/ca-certificates.crt
  • found 694 certificates in /etc/ssl/certs
  • ALPN, offering http/1.1
  • SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
  • server certificate verification OK
  • server certificate status verification SKIPPED
  • common name: incapsula.com (matched)
  • server certificate expiration date OK
  • server certificate activation date OK
  • certificate public key: RSA
  • certificate version: #3
  • subject: C=US,ST=Delaware,L=Dover,O=Incapsula Inc,CN=incapsula.com
  • start date: Wed, 28 Mar 2018 07:33:51 GMT
  • expire date: Tue, 16 Oct 2018 09:29:59 GMT
  • issuer: C=BE,O=GlobalSign nv-sa,CN=GlobalSign CloudSSL CA - SHA256 - G3
  • compression: NULL
  • ALPN, server did not agree to a protocol

GET / HTTP/1.1
Host: beta.check-mot.service.gov.uk
User-Agent: curl/7.47.0
Accept: application/json
x-api-key: API KEY

< HTTP/1.1 403 Forbidden
< Content-Type: application/json
< Content-Length: 43
< Connection: keep-alive
< Date: Thu, 19 Apr 2018 02:23:32 GMT
< x-amzn-RequestId: a7b95f2a-4378-11e8-823e-1707b1755be6
< x-amzn-ErrorType: MissingAuthenticationTokenException
< x-amz-apigw-id: FkSRrEcqjoEFtEA=
< X-Cache: Error from cloudfront
< Via: 1.1 db29ce630f36ae7f48a6957d9d80d0be.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: on1G43o2CYZFH2yRcsUP3oHYZQQhWgw76nPyf8Y2vV_zJOy1yeqh2g==
< Set-Cookie: visid_incap_1151098=X2wckoG7QmybXDPqnkMqq6P911oAAAAAQUIPAAAAAADGm6ee6C6EhpemMK9YwpYd; expires=Thu, 18 Apr 2019 12:14:28 GMT; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: nlbi_1151098=OTNSeizpYUF7Qr0BR22hbQAAAABu3Md5TDawJ/lVqbRs89aW; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: incap_ses_374_1151098=snDnCPTc/UoDDCP/N7cwBaP911oAAAAA/MtqNe7LCKrwvTTtEI8f3A==; path=/; Domain=.check-mot.service.gov.uk
< Set-Cookie: ___utmvmSNukcFcB=AAgXhOmvhYx; path=/; Max-Age=900
< Set-Cookie: ___utmvaSNukcFcB=XvV�lOYx; path=/; Max-Age=900
< Set-Cookie: ___utmvbSNukcFcB=oZn
< XjyOUalR: itK; path=/; Max-Age=900
< X-Iinfo: 6-48709975-48709978 NNNN CT(1 6 0) RT(1524104611734 108) q(0 0 0 0) r(0 0) U5
< X-CDN: Incapsula
<
{"message":"Missing Authentication Token"}

  • Connection #0 to host wwwproxy.hud.ac.uk left intact

@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