5

The API url is =, i'm trying to implement: https://docs.ingresso.co.uk/#basic-booking-flow

My Code for in OctoberCMS with GuzzleHttp\Client object.

    $credentials = base64_encode('demo:demopass');
    $client = new Client();
    $request_url = 'https://demo.ticketswitch.com/f13/events.v1/';
    $response = $client->request('GET', $request_url, [
        'headers' => ['Accept' => 'application/json','Authorization' => 'Basic ' . $credentials,],
        'auth'    => ['demo', 'demopass'],
        'timeout' => 120
    ])->getBody()->getContents();

    echo "<pre>";
    print_r($response);
    die();

The error got by sending the request is enter image description here

i'm reading all suggested question while i'm adding my title for question and there is no clue or help regarding the problem... Help.....

Note: Api credentials can use by any user or developer,

1 Answers1

3

The error indicates the request must gzip: "You must support gzip [to use this API]".

This is controlled via the Accept-Encoding header sent to the server:

The Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand..

The server is enforcing this to ensure clients save bandwidth, through use of compression, when using the API. This may reduce the hosting costs and/or improve request performance. The F13 documentation simply notes "gzip must be used for all requests".

Use of enabling gzip transport compression is covered in the Guzzle Request Options documentation:

// Request gzipped data and automatically decode/decompress it
$client->request('GET', '/foo.js', [
    'headers'        => ['Accept-Encoding' => 'gzip'],
    'decode_content' => true  // default is true, added to be explicit
]);

or, more simply

// Pass "gzip" as the Accept-Encoding header and automatically decode/decompress
$client->request('GET', '/foo.js', ['decode_content' => 'gzip']);

When [decode_content is set] to a string, the bytes of a response are decoded and the string value provided to the decode_content option is passed as the Accept-Encoding header of the request.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • thanks @user2864740 <3 and how to use basic auth in this code? – Muhammad Awais Zulifqar Jul 04 '18 at 07:16
  • @MuhammadAwaisZulifqar The other headers/options remain the same. Add them all together. Using the simpler `'decode_content' => 'gzip'` approach should make this simpler and more clear (ie. it can be added directly below the `timeout => 120` line). – user2864740 Jul 04 '18 at 07:17
  • $response = $client->request('GET', $request_url, [ 'headers' => ['Accept-Encoding' => 'gzip','auth' => ['demo', 'demopass']], 'decode_content' => true ])->getBody()->getContents(); trying this but not working? – Muhammad Awais Zulifqar Jul 04 '18 at 07:18
  • 1
    @MuhammadAwaisZulifqar Is it a *different* error? If so, it's a *different* question. Also, that code is different from that which is shown in the question.. I very much *doubt* 'auth' is a Header, so that's a step-backwards as written. – user2864740 Jul 04 '18 at 07:18
  • sorry , it's working thanks dear with small change... $response = $client->request('GET', $request_url, [ 'headers' => ['Accept-Encoding' => 'gzip'], 'decode_content' => true, 'auth' => ['demo', 'demopass'] ])->getBody()->getContents(); – Muhammad Awais Zulifqar Jul 04 '18 at 07:20
  • 1
    Cool. It can also be written as: `$client->request('GET', $request_url, [ 'decode_content' => 'gzip', 'auth' => ['demo', 'demopass'] ])`; I covered the Accept-Encoding header "explicitly" first as background information. – user2864740 Jul 04 '18 at 07:20