PHP code example of james-and-james-fulfilment / amazon-sp-api
1. Go to this page and download the library: Download james-and-james-fulfilment/amazon-sp-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/ */
james-and-james-fulfilment / amazon-sp-api example snippets
public function getAccessToken($channel_account): string
{
$refresh_token = $channel_account->getAuthDetail('refresh_token');
if (!$refresh_token) {
throw new AmazonSPAPIOAuthException('Invalid refresh_token');
}
return AmazonSPAPIOAuth::getAccessTokenFromRefreshToken(
$refresh_token,
$this->client_id,
$this->client_secret
);
}
public function prepareRequestConfig($channel_account, $token): array
{
$auth_details = $channel_account->getAuthDetail();
$region_key = $auth_details['region'];
$region = AmazonSPAPIRegion::$$region_key;
$endpoint = AmazonSPAPIEndpoint::$$region_key;
$assumedRole = AssumeRole::assume(
$region,
$this->iam_user_access_key,
$this->iam_user_secret_key,
$this->iam_role_arn,
);
$config = Configuration::getDefaultConfiguration();
$config->setAccessToken($token);
$config->setAccessKey($assumedRole->getAccessKeyId());
$config->setSecretKey($assumedRole->getSecretAccessKey());
$config->setRegion($region);
$config->setSecurityToken($assumedRole->getSessionToken());
return $config;
}