PHP code example of tcgpricelookup / sdk

1. Go to this page and download the library: Download tcgpricelookup/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/ */

    

tcgpricelookup / sdk example snippets




cgPriceLookup\Client;

$client = new Client('tlk_live_...');

$results = $client->cards->search([
    'q' => 'charizard',
    'game' => 'pokemon',
    'limit' => 5,
]);

foreach ($results['data'] as $card) {
    echo $card['name'] . ' — ' . $card['set']['name'] . PHP_EOL;
}

// Search
$client->cards->search([
    'q' => 'blue-eyes white dragon',
    'game' => 'yugioh',  // pokemon | mtg | yugioh | onepiece | lorcana | swu | fab
    'set' => 'lob',
    'limit' => 20,
    'offset' => 0,
]);

// Get one
$card = $client->cards->get('<card-uuid>');

// Daily price history (Trader plan)
$history = $client->cards->history('<card-uuid>', ['period' => '30d']);

$sets = $client->sets->list(['game' => 'mtg', 'limit' => 50]);

$games = $client->games->list();
foreach ($games['data'] as $game) {
    echo $game['slug'] . ': ' . $game['count'] . ' cards' . PHP_EOL;
}

$results = $client->cards->search([
    'ids' => ['uuid1', 'uuid2', /* ... */],
]);

use TcgPriceLookup\Exception\{
    AuthenticationException,
    PlanAccessException,
    NotFoundException,
    RateLimitException,
};

try {
    $history = $client->cards->history('<uuid>', ['period' => '1y']);
} catch (AuthenticationException $e) {
    echo "Bad API key\n";
} catch (PlanAccessException $e) {
    echo "History 

$client = new Client('tlk_live_...', [
    'base_url' => 'https://api.tcgpricelookup.com/v1',
    'timeout' => 60.0,
    'user_agent' => 'my-app/1.0',
]);