jasara / laravel-selling-partner-api

Laravel wrapper for Amazon's Selling Partner API SDK
https://phpspa.com
MIT License
7 stars 4 forks source link

my easiest example won't work, credentials are tested in postman #1

Closed tabbedy closed 2 years ago

tabbedy commented 2 years ago
    Hello everybody,
    i try to create a quite easy example to learn using the new selling partner api with this SDK, but it won't work...

    i testet my values in postman before, in postman i receive the access token, inside the using of the sdk, not. Please take a look at my easy example:
 $config = new AmznSPAConfig(
            marketplace_id: 'A1PA6795UKMFR9',
            application_id: '***',

            lwa_refresh_token: '****',
            lwa_client_id: '*****',
            lwa_client_secret: '*****',
            //lwa_access_token:, // I want to receive it
            aws_access_key: '****',
            aws_secret_key: '****',
        );

        $spa = new AmznSPA($config);
        #

        $lwa_access_token = $spa->getAccessToken(); // Get the latest access token.
        return $lwa_access_token;

another issue i have, when i set the received access token manually and make a call

$items = $spa->catalog->getItems();

there is no catalog, because the element $spa does not contain a catalog node... a year ago i worked with kitebrink laravel mws pretty well and i build a small application for my own seller account, but here i am a little bit helpless.

does anybody has a representative easy example which will work with correct credentials?

best regards Patrick

keithbrink commented 2 years ago

Patrick,

The package will automatically manage your access tokens. You can add another parameter to AmznSPAConfig called save_lwa_tokens_callback if you would like to store/cache your access tokens. Here's an example:

use Illuminate\Support\Facades\Cache;
use Jasara\AmznSPA\DataTransferObjects\AuthTokensDTO;

new AmznSPAConfig(
    lwa_access_token: Cache::get('spa:lwa_access_token'),
    save_lwa_tokens_callback: function (AuthTokensDTO $tokens) {
        Cache::put('spa:lwa_access_token', $tokens->access_token, $tokens->expires_at);
    },
    ...
);
keithbrink commented 2 years ago

Here is the correct call for the catalog items:

$this->spa->catalog_items->getCatalogItem(asin: 'ASIN', marketplace_ids: ['MARKETPLACE_IDS']);