Skip to content

Commit 083516b

Browse files
Merge pull request #20 from MST1122/master
getCredentials('grantless') for grantless operations
2 parents ccdf2bd + bb37dcf commit 083516b

5 files changed

Lines changed: 235 additions & 132 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
codelab/
33
test.php
44
aws-tokens
5+
.idea

README.md

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Author: Lyubomir Slavilov
66
## Before you start
77
Spapi is released as Composer package `double-break/spapi-php` with **no warranties or promises**.
88

9-
There are couple classes (such as `Signer`, `Credentials`) which are esential for the API calls to work. Most of the issues will live here.
9+
There are couple classes (such as `Signer`, `Credentials`) which are essential for the API calls to work. Most of the issues will live here.
1010

11-
All of the actual API clients are autogenerated and given the disclamer above - not heavely tested.
11+
All of the actual API clients are autogenerated and given the disclaimer above - not heavily tested.
1212

1313
### Requirements
1414
- php 7.3 (never tested on lower version)
@@ -88,6 +88,7 @@ Name | Description | Type
8888

8989
//Create Credentials service and call getCredentials() to obtain
9090
//all the tokens needed under the hood
91+
9192
$credentials = new DoubleBreak\Spapi\Credentials($tokenStorage, $signer, $config);
9293
$cred = $credentials->getCredentials();
9394

@@ -96,11 +97,11 @@ Name | Description | Type
9697
/** The application logic implementation **/
9798

9899

99-
//Create SP API Catalog client and execute one ot its REST methds.
100-
$catalogClinet = new DoubleBreak\Spapi\Api\Catalog($cred, $config);
100+
//Create SP API Catalog client and execute one ot its REST methods.
101+
$catalogClient = new DoubleBreak\Spapi\Api\CatalogItems($cred, $config);
101102

102103
//Check the catalog info for B074Z9QH5F ASIN
103-
$result = $catalogClinet->getCatalogItem('B074Z9QH5F', [
104+
$result = $catalogClient->getCatalogItem('B074Z9QH5F', [
104105
'MarketplaceId' => 'A1PA6795UKMFR9',
105106
])['payload'];
106107

@@ -278,4 +279,60 @@ $result = $authorizationClient->getAuthorizationCode([
278279

279280
//Authorization code should be changed to Access and Refresh token
280281
print_r($credentials->exchangesAuthorizationCodeForRefreshToken($result['authorizationCode']));
282+
```
283+
284+
### Authorization for Grantless Operations in Selling Partner API
285+
286+
[Please, see more details in Selling Partner Api docs](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#grantless-operations-1)
287+
288+
```php
289+
<?php
290+
include __DIR__ . '/vendor/autoload.php';
291+
292+
/** The Setup **/
293+
294+
$config = [
295+
//Guzzle configuration
296+
'http' => [
297+
'verify' => false,
298+
'debug' => true
299+
],
300+
301+
//LWA: Keys needed to obtain access token from Login With Amazon Service
302+
'refresh_token' => '<YOUR-REFRESH-TOKEN>',
303+
'client_id' => '<CLINET-ID-IN-SELLER-CONSOLE>',
304+
'client_secret' => '<CLIENT_SECRET>',
305+
306+
//STS: Keys of the IAM role which are needed to generate Secure Session
307+
// (a.k.a Secure token) for accessing and assuming the IAM role
308+
'access_key' => '<STS-ACCESS_KEY>',
309+
'secret_key' => '<STS-SECRET-KEY>',
310+
'role_arn' => '<ROLE-ARN>' ,
311+
312+
//API: Actual configuration related to the SP API :)
313+
'region' => 'eu-west-1',
314+
'host' => 'sellingpartnerapi-eu.amazon.com'
315+
];
316+
317+
//Create token storage which will store the temporary tokens
318+
$tokenStorage = new DoubleBreak\Spapi\SimpleTokenStorage('./aws-tokens');
319+
320+
//Create the request signer which will be automatically used to sign all of the
321+
//requests to the API
322+
$signer = new DoubleBreak\Spapi\Signer();
323+
324+
//Create Credentials service and call getCredentials() to obtain
325+
//all the tokens needed under the hood
326+
$credentials = new DoubleBreak\Spapi\Credentials($tokenStorage, $signer, $config);
327+
//get credentials with Grantless auth token, it's needed for grantless operations request
328+
$cred = $credentials->getCredentials('grantless');
329+
330+
/** The application logic implementation **/
331+
332+
//Create SP API Notification client and execute one ot its REST methods.
333+
$notificationClient = new DoubleBreak\Spapi\Api\Notifications($cred, $config);
334+
335+
//Get notification destinations
336+
$result = $notificationClient->getDestinations();
337+
print_r($result['payload']);
281338
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"require": {
1212
"guzzlehttp/guzzle": "^6.5",
1313
"guzzlehttp/psr7": "^1.7",
14-
"patchwork/utf8": "~1.2",
1514
"ext-simplexml": "*",
16-
"ext-json": "*"
15+
"ext-json": "*",
16+
"ext-zlib": "*"
1717
},
1818
"autoload": {
1919
"psr-4": { "DoubleBreak\\Spapi\\" : "src/" }

0 commit comments

Comments
 (0)