Skip to content

JamesAndJamesFulfilment/amazon-sp-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwaggerClient-php

The Selling Partner API for Listings Items (Listings Items API) provides programmatic access to selling partner listings on Amazon. Use this API in collaboration with the Selling Partner API for Product Type Definitions, which you use to retrieve the information about Amazon product types needed to use the Listings Items API. For more information, see the Listings Items API Use Case Guide.

This PHP package is automatically generated by the Swagger Codegen project:

Usage

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;
}