Generate RDT Token for the restricted APIs #202
-
Hello, I have implemented pull order functionality using this SDK. Here's what I have implemented, I am able to retrieve orders and order items but I am not able to fetch buyer information and shipping address, for that, I have to replace Access Token with Restricted Data Token but I am not able to implement RDT in this process can you please Help/Guide me that how I can implement RDT in this! and also is this appropriate way to integrate SDK like this? if not then can you please guide me so I can update accordingly? `
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
hey, could you please start from providing the error message you are getting from Amazon? |
Beta Was this translation helpful? Give feedback.
-
Please find a working example of accessing buyerInfo and shippingAddress below: <?php
use AmazonPHP\SellingPartner\AccessToken;
use AmazonPHP\SellingPartner\Model\Tokens\RestrictedResource;
use AmazonPHP\SellingPartner\Regions;
use AmazonPHP\SellingPartner\SellingPartnerSDK;
use Buzz\Client\Curl;
use AmazonPHP\SellingPartner\Configuration;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Nyholm\Psr7\Factory\Psr17Factory;
use AmazonPHP\SellingPartner\Model\Tokens\CreateRestrictedDataTokenRequest;
require_once __DIR__ . '/vendor/autoload.php';
$factory = new Psr17Factory();
$client = new Curl($factory);
$sellerId = 'xxx';
$sellerRefreshToken = 'xxx';
$clientId = 'xxx';
$clientSecret = 'xxx';
$accessKey = 'xxx';
$secretKey = 'xx';
$orderId = 'xxx-xxxxxxx-xxxxxxx';
$configuration = Configuration::forIAMUser(
$clientId,
$clientSecret,
$accessKey,
$secretKey
);
$logger = new Logger('name');
$logger->pushHandler(new StreamHandler(__DIR__ . '/sp-api-php.log', Logger::DEBUG));
$sdk = SellingPartnerSDK::create($client, $factory, $factory, $configuration, $logger);
$accessToken = $sdk->oAuth()->exchangeRefreshToken($sellerRefreshToken);
$restrictedDataAccessToken = $sdk->tokens()->createRestrictedDataToken(
$accessToken,
Regions::NORTH_AMERICA,
new CreateRestrictedDataTokenRequest([
'restricted_resources' => [
new RestrictedResource([
'method' => RestrictedResource::METHOD_GET,
'path' => '/orders/v0/orders/{orderId}',
'data_elements' => ['buyerInfo', 'shippingAddress'],
]),
],
])
);
$order = $sdk->orders()->getOrder(
new AccessToken(
$restrictedDataAccessToken->getRestrictedDataToken(),
'not_available',
'bearer',
$restrictedDataAccessToken->getExpiresIn(),
'restricted_data_token'
),
Regions::NORTH_AMERICA,
$orderId
);
dump($order); That's the best I can do, I'm not doing any consulting over social media or any other communication channels, this library is generated from amazon models repository so it should work as long as you are following docs |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Please find a working example of accessing buyerInfo and shippingAddress below: