PHP code example of getmytg / gmt-php-sdk

1. Go to this page and download the library: Download getmytg/gmt-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getmytg / gmt-php-sdk example snippets




use Gmt\Client;

$client = new Client(apiKey: getenv('x-api-key') ?: 'My API Key');

$response = $client->service->healthCheck();

var_dump($response->now);



use Gmt\Client;

$client = new Client(apiKey: getenv('x-api-key') ?: 'My API Key');

$page = $client->purchases->list(['page' => 1, 'page_size' => 100]);

var_dump($page);

// fetch items from the current page
foreach ($page->getItems() as $item) {
  var_dump($item->id);
}
// make additional network requests to fetch items from all pages, including and after the current page
foreach ($page->pagingEachItem() as $item) {
  var_dump($item->id);
}



use Gmt\Core\Exceptions\APIConnectionException;

try {
  $response = $client->service->healthCheck();
} catch (APIConnectionException $e) {
  echo "The server could not be reached", PHP_EOL;
  var_dump($e->getPrevious());
} catch (RateLimitError $_) {
  echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusError $e) {
  echo "Another non-200-range status code was received", PHP_EOL;
  echo $e->getMessage();
}



use Gmt\Client;
use Gmt\RequestOptions;

// Configure the default for all requests:
$client = new Client(maxRetries: 0);

// Or, configure per-request:
$result = $client->service->healthCheck(RequestOptions::with(maxRetries: 5));



use Gmt\RequestOptions;

$response = $client->service->healthCheck(
  RequestOptions::with(
    extraQueryParams: ['my_query_parameter' => 'value'],
    extraBodyParams: ['my_body_parameter' => 'value'],
    extraHeaders: ['my-header' => 'value'],
  ),
);



$response = $client->request(
  method: "post",
  path: '/undocumented/endpoint',
  query: ['dog' => 'woof'],
  headers: ['useful-header' => 'interesting-value'],
  body: ['hello' => 'world']
);