PHP code example of daikazu / asi-smartlink

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

    

daikazu / asi-smartlink example snippets


use Daikazu\AsiSmartlink\Enums\ProductSort;
use Daikazu\AsiSmartlink\Facades\AsiSmartlink;

$results = AsiSmartlink::products()->search(
    query: 'mugs',
    page: 1,
    resultsPerPage: 25,
    sort: ProductSort::PriceLowToHigh,
    dimensionLists: ['supplier', 'category'],
);

$results->resultsTotal;          // 20552
$results->hasNextPage();         // true

foreach ($results->products as $product) {
    $product->name;              // "Purple Plush Santa Hat"
    $product->number;            // "HAT112"
    $product->supplier?->name;   // "Brighter Promotions Inc"
    $product->prices[0]?->price; // 3.68
}

use Daikazu\AsiSmartlink\Http\SmartLinkConnector;
use Daikazu\AsiSmartlink\Support\ProductQuery;

$smartlink = new SmartLinkConnector(
    baseUrl: 'https://api.asicentral.com',
    clientId: 123456,
    clientSecret: getenv('ASI_SMARTLINK_SECRET'),
);

$results = $smartlink->products()->search(
    ProductQuery::make('pen')->hasImage()->priceBetween(1, 5)
);

use Daikazu\AsiSmartlink\Facades\AsiSmartlink;
use Daikazu\AsiSmartlink\Enums\AutoCompleteDimension;
use Daikazu\AsiSmartlink\Enums\MediaSize;

// Products
AsiSmartlink::products()->search('mugs');
AsiSmartlink::products()->get(4815380);                 // full detail
AsiSmartlink::products()->getByCpn('12345');            // CPN lookup
AsiSmartlink::products()->configure(4815380, configId: 1);
AsiSmartlink::products()->matrix(4694711);              // apparel price grid
AsiSmartlink::products()->charges(4815380);             // list<ProductCharge>
AsiSmartlink::products()->lookupCharges();              // master charge list
AsiSmartlink::products()->deletedSince('11/02/2016');   // list<int>

// Suppliers & decorators
AsiSmartlink::suppliers()->search('promotions');
AsiSmartlink::suppliers()->get(875);
AsiSmartlink::decorators()->search('promotions');
AsiSmartlink::decorators()->get(6859235);

// Lists (no auth 

use Daikazu\AsiSmartlink\Facades\AsiSmartlink;
use Daikazu\AsiSmartlink\Support\ProductQuery;

$query = ProductQuery::make('pen')
    ->preferred(1, 2, 3)        // preferred supplier ranks 1-5 (or ->preferredAll() for *)
    ->category('Pens')
    ->priceBetween(1.00, 3.00)  // price:[1 to 3]
    ->hasImage()                // boolean filters: has_image:1
    ->isNew();

AsiSmartlink::products()->search($query, resultsPerPage: 25);
// q => "pen preferred:1,2,3 category:Pens price:[1 to 3] has_image:1 is_new:1"

use Daikazu\AsiSmartlink\Support\SupplierQuery;

// Filter-only search — suppliers in Philadelphia, PA, rated 4+
AsiSmartlink::suppliers()->search(
    SupplierQuery::make()
        ->state('PA')              // postal abbreviation
        ->city('Philadelphia')
        ->supplierRating(4)        // minimum rating; emits rating:4
);
// q => "state:PA city:Philadelphia rating:4"

use Daikazu\AsiSmartlink\Support\DecoratorQuery;

AsiSmartlink::decorators()->search(
    DecoratorQuery::make('embroidery')->state('FL')->city('Miami')
);
// q => "embroidery state:FL city:Miami"

use Daikazu\AsiSmartlink\Enums\AutoCompleteDimension;
use Daikazu\AsiSmartlink\Facades\AsiSmartlink;
use Daikazu\AsiSmartlink\Support\ProductQuery;

// 1. user types "bl" in the colour field — suggest matching values
$suggestions = AsiSmartlink::lists()->autoComplete(AutoCompleteDimension::Color, 'bl');
// ["Black Shades", "Blue Shades", "Bright Blue", ...]

// 2. user picks one — feed the exact value into the search filter
$results = AsiSmartlink::products()->search(
    ProductQuery::make('shirt')->color('Blue Shades')
);

use Daikazu\AsiSmartlink\Exceptions\AuthenticationException;
use Daikazu\AsiSmartlink\Exceptions\ResourceNotFoundException;
use Daikazu\AsiSmartlink\Exceptions\RateLimitExceededException;
use Daikazu\AsiSmartlink\Exceptions\SmartLinkRequestException;

try {
    $product = AsiSmartlink::products()->get(4815380);
} catch (ResourceNotFoundException $e) {
    // 404 — {"Error":"Product not found"}
} catch (AuthenticationException $e) {
    // 401/403 — bad or missing client_id / client_secret
} catch (RateLimitExceededException $e) {
    // 429 — hourly limit (5,000) exceeded
    $e->limit();      // 5000
    $e->remaining();  // 0
    $e->reset();      // X-Rate-Limit-Reset
} catch (SmartLinkRequestException $e) {
    // any other API error (e.g. 5xx)
    $e->getStatus();    // HTTP status code
    $e->error();        // ASI "Error" message (null if the body wasn't JSON)
    $e->getResponse();  // the underlying Saloon response
}
bash
php artisan vendor:publish --tag="asi-smartlink-config"