jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
398 stars 185 forks source link

getAuthorizationCode Migrating MWS Tokens to Sp API shows 403 access denied #351

Closed chrismeats closed 2 years ago

chrismeats commented 2 years ago

Problem description:

I am attempting to migrate users MWS auth tokens to SPAPI however, I am getting the below access denied/unauthorized response when trying to call getAuthorizationCode and am at a bit of a loss on where to go from here.

My SP API is in a published status.

Anyone experience this or have any idea on where to go from here?

Error:

   SellingPartnerApi\ApiException 

  [403] {
  "errors": [
    {
      "message": "Access to requested resource is denied.",
     "code": "Unauthorized",
     "details": ""
    }
  ]
}

Code

$config = new Configuration([
            "lwaClientId"        => env('LWA_CLIENT_ID'),
            "lwaClientSecret"    => env('LWA_CLIENT_SECRET'),
            "awsAccessKeyId"     => env('AMAZON_ACCESS_KEY_ID'),
            "awsSecretAccessKey" => env('AMAZON_SECRET_ACCESS_KEY'),
            "endpoint"           => Endpoint::NA,  // or another endpoint from lib/Endpoints.php
        ]);

        $apiInstance = new AuthorizationV1Api($config);
        $selling_partner_id = $shopId;
        $developer_id = env('AMAZON_DEVELOPER_ID');
        $mws_auth_token = $mwsAuthToken;

        try {
            $result = $apiInstance->getAuthorizationCode($selling_partner_id, $developer_id, $mws_auth_token);
            dd($result);
        } catch (Exception $e) {
            echo 'Exception when calling AuthorizationApi->getAuthorizationCode: ', $e->getMessage(), PHP_EOL;
        }
chrismeats commented 2 years ago

Never mind, This was a stupid mistake. I was using some old code from when I started this migration process a year ago and I had the wrong awsAccessKeys loaded in! :|