PHP code example of navneetbhardwaj / awssdk

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

    

navneetbhardwaj / awssdk example snippets





SpApi\AuthAndAuth\LWAAuthorizationCredentials;
use SpApi\Configuration;
use SpApi\Api\orders\v0\OrdersV0Api;


// Set up LWA credentials
$lwaAuthorizationCredentials = new LWAAuthorizationCredentials([
"clientId" => "amzn1.application-**************",
"clientSecret" => "***********",
"refreshToken" => "***********",
"endpoint" => "https://api.amazon.com/auth/o2/token"
]);

//Initialize config
$config = new Configuration([], $lwaAuthorizationCredentials);

// Setting SP-API endpoint region
$config->setHost('https://sellingpartnerapi-na.amazon.com');

// Create a new HTTP client
$client = new GuzzleHttp\Client();

// Create an instance of the Orders Api
$api = new OrdersV0Api($config, $client);

try {
    // Call getOrders
    $result = $api->getOrders(
        $marketplace_ids = ['ATVPDKIKX0DER'],
        $created_after = '2025-01-01'
    );
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling OrderApi->getOrders: ', $e->getMessage(), PHP_EOL;
}

$api = new OrdersV0Api($config, $client, false);

$rateLimitConfiguration = [
    'id' => 'spApi',
    'policy' => 'token_bucket',
    'limit' => 5, // capacity of bucket
    'rate' => [ // refill rate
        'interval' => '1 second',
        'amount' => 50
    ],
];

$factory = new RateLimiterFactory($rateLimitConfiguration, new InMemoryStorage());
$api->getOrderRateLimiter = $factory->create("<insert-unique-id>"); // Use unique id in create-method