PHP code example of slimad / colnect-api

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

    

slimad / colnect-api example snippets




limad\ColnectApi\ColnectConnector;
use Slimad\ColnectApi\Enums\CategoryType;
use Slimad\ColnectApi\Requests\Category\GetCountriesRequest;
use Slimad\ColnectApi\Requests\Category\GetItemsListRequest;
use Slimad\ColnectApi\Requests\General\GetCategoriesRequest;
use Slimad\ColnectApi\Requests\Search\GlobalSearchRequest;
use Slimad\ColnectApi\Support\Filters;

$connector = new ColnectConnector(
    appId:     getenv('COLNECT_APP_ID'),
    appSecret: getenv('COLNECT_APP_SECRET'),
    language:  'en',
    userAgent: 'MyCoolApp/1.2.3.4',
);

// 1. List every supported collectable category
$categories = $connector->send(new GetCategoriesRequest())->json();

// 2. List the countries that issued a given collectable category
$countries = $connector
    ->send(new GetCountriesRequest(CategoryType::Stamps))
    ->json();

// 3. List the items of a country, newest first
$items = $connector
    ->send(new GetItemsListRequest(
        CategoryType::Stamps,
        Filters::make()->producer(2610)->year(1980),
    ))
    ->json();

// 4. Search across a collectable type
$results = $connector
    ->send(new GlobalSearchRequest(CategoryType::Stamps, 'olympic games', page: 2))
    ->json();

$connector = new ColnectConnector(
    appId:     'your-app-id',
    appSecret: 'your-app-secret',
    language:  'pl',                 // resolves to https://api.colnect.net/pl/api/{appId}
    userAgent: 'MyCoolApp/1.2.3.4',  // must clearly identify your app, 16+ characters
);

$request  = new GetCountriesRequest(CategoryType::Coins);
$response = $connector->send($request);

$body   = $response->body();   // raw string
$json   = $response->json();   // array
$status = $response->status(); // int

use Slimad\ColnectApi\Enums\CategoryType;

CategoryType::Coins;              // 'coins'
CategoryType::Stamps;             // 'stamps'
CategoryType::Banknotes;          // 'banknotes'
CategoryType::TradingCardGames;   // 'trading_card_games'
// ...46 categories in total

new GetCountriesRequest(CategoryType::Stamps); // typed
new GetCountriesRequest('stamps');             // string, still valid

CategoryType::Phonecards->producerFilter();   // 'company'
CategoryType::Stamps->producerFilter();       // 'country'
CategoryType::Stamps->producerIsCountry();    // true

use Slimad\ColnectApi\Support\Filters;

$filters = Filters::make()
    ->country(5)
    ->year(1980)
    ->theme(7)
    ->sort('face_value')   // see GetCategorySortOptionsRequest
    ->page(2);

$connector->send(new GetItemsListRequest(CategoryType::Stamps, $filters));
// GET /list/cat/stamps/country/5/year/1980/theme/7/sort/face_value/page/2

Filters::make()->with('in_stock', 1);

$fields = $connector->send(new GetFieldTitlesRequest(CategoryType::Coins))->json();
$item   = $connector->send(new GetItemRequest(CategoryType::Coins, 35693))->json();

// Up to 50 items per call - the response is then an array of arrays
$items = $connector->send(new GetItemRequest(CategoryType::Coins, [35693, 12594]))->json();

// Resolve referenced records (themes, catalog codes, ...) in the same call
$detailed = $connector->send(new GetItemRequest(CategoryType::Coins, 35693, 

use Slimad\ColnectApi\Enums\PictureSize;
use Slimad\ColnectApi\Support\PictureUrl;

PictureUrl::item(142891, 'Pasteur-Louis');
// https://i.colnect.net/images/t/142/891/Pasteur-Louis.jpg

PictureUrl::item(1234567, 'Some Name', PictureSize::Full);
// https://i.colnect.net/images/f/1234/567/Some_Name.jpg

PictureUrl::flag(469);
// https://i.colnect.net/flag/32/469-country.png

use Slimad\ColnectApi\Enums\ItemsInSale;
use Slimad\ColnectApi\Requests\Marketplace\GetItemSalesRequest;
use Slimad\ColnectApi\Requests\Marketplace\GetMarketPricesRequest;

// Sale prices of the last 30 days, per condition
$prices = $connector
    ->send(new GetMarketPricesRequest(CategoryType::Coins, [35693, 12594], days: 30))
    ->json();

// Up to 20 single-item sales currently on the market
$sales = $connector
    ->send(new GetItemSalesRequest(CategoryType::Coins, 35693, ItemsInSale::Single, maxSales: 20))
    ->json();

use Slimad\ColnectApi\Requests\Search\ImageSearchRequest;
use Slimad\ColnectApi\Support\ImageSearchTarget;

$target = ImageSearchTarget::fromUrl('https://example.com/coin-front.jpg')
    ->withBackUrl('https://example.com/coin-back.jpg'); // coins only

$matches = $connector
    ->send(new ImageSearchRequest($target, CategoryType::Coins, Filters::make()->country(5)))
    ->json();

use Slimad\ColnectApi\Exceptions\InvalidArgumentException;

try {
    new GetItemRequest(CategoryType::Coins, range(1, 51)); // 50 IDs max
} catch (InvalidArgumentException $e) {
    // 'Item IDs must not contain more than 50 IDs.'
}

use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Slimad\ColnectApi\ColnectConnector;
use Slimad\ColnectApi\Requests\General\GetLanguagesRequest;

$mockClient = new MockClient([
    GetLanguagesRequest::class => MockResponse::make([
        'en' => 'English',
        'pl' => 'Polski',
    ], status: 200),
]);

$connector = (new ColnectConnector('app_id', 'app_secret'))
    ->withMockClient($mockClient);

$languages = $connector->send(new GetLanguagesRequest())->json();