double-break / spapi-php

Amazon Selling Partner API PHP Client
MIT License
56 stars 46 forks source link

API getAuthorizationCode 500 Internal Server Error #50

Closed fruch17 closed 2 years ago

fruch17 commented 2 years ago

Hello, i have an issue with the api getAuthorizationCode , I'm trying to Migrate an Amazon MWS authorization to a Selling Partner API application for a client who already has MWS authorization with us.

This is the error:

Server error: GET https://sellingpartnerapi-na.amazon.com/authorization/v1/authorizationCode?developerId=99XXXXXX364&mwsAuthToken=amzn.mws.XXXXX-XXXXX-XXXX-XXXXX&sellingPartnerId=A1XXXXXXXXW resulted in a 500 Internal Server Error response: { "errors": [ { "code": "InternalFailure", "message": "We encountered an internal error. Please try ag (truncated...)

PLEASE , I NEED SOME HELP ... I would be very grateful

This is my code that is like the example in the main page (https://github.com/double-break/spapi-php):

$config = [ 'http' => [ 'verify' => false, //<--- NOT SAFE FOR PRODUCTION 'debug' => false //<--- NOT SAFE FOR PRODUCTION ], 'client_id' => "amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxx", // developer account 'client_secret' =>"xxxxxxxxxxxxxxxxxxxx", // developer account 'access_key' => "xxxxxxxxx", // user credencial aws console 'secret_key' => "8wH1/xxxxxxxxxxxxx+g+pP+YJ", // user credencial aws console 'role_arn' => 'arn:aws:iam::xxxxxxxxxxx:role/skusuite_spapi' , // user credencial aws console
'region' => "us-east-1", 'host' => "sellingpartnerapi-na.amazon.com"

    ];

      //Create token storage which will store the temporary tokens
    $table_id = 'tmp_';
    $file_name_aws_tokens = $table_id. 'aws_tokens.json';
    File::put('/tmp/'.$file_name_aws_tokens ,'');
    $tokenStorage = new SimpleTokenStorage('/tmp/'.$file_name_aws_tokens); 

    //Create the request signer which will be automatically used to sign all of the
    //requests to the API
    $signer = new Signer();

    //Create Credentials service and call getCredentials() to obtain
    //all the tokens needed under the hood
    $credentials = new Credentials($tokenStorage, $signer, $config);
    //get credentials with migration token, it's needed for /authorization/v1/authorizationCode request
    $cred = $credentials->getCredentials(true);

    /** The application logic implementation **/

    //Create SP API Catalog client and execute one ot its REST methods.
    $authorizationClient = new Authorization($cred, $config);

    //Get Authorization code
    $result = $authorizationClient->getAuthorizationCode([
        'developerId' => '99XXXXXXXX64',
        'mwsAuthToken' => 'amzn.mws.XXXXXXX-XXXX-XXX-XXX-XXXXXXX',
        'sellingPartnerId' => 'A1XXXXXXXXXT9W'
    ])['payload'];
    print_r($result);die;
    //Authorization code should be changed to Access and Refresh token
    print_r($credentials->exchangesAuthorizationCodeForRefreshToken($result['authorizationCode']));

Please help...

lyubo-slavilov commented 2 years ago

Hello there. As per the dumps you provided it seems the HTTP 500 error originates in Amazon API itself.

They actually saying

We encountered an internal error. Please try ag(ain later)

I am not sure how to help here.May be @MST1122 can give some more details since he (assuming) dealt with migration from MWS to SP API

FatmaSedaOZYURT commented 2 years ago

I have the same problem. Somebodies tell this problem may have been gotten in wrong request. But, when I viewed in this document , I see correctly request. My response is: { "errors": [ { "code": "InternalFailure", "message": "We encountered an internal error. Please try again.", "details": "" } ] } @fruch17 Did you find solution?

CesarObedFL commented 2 years ago

@FatmaSedaOZYURT i´m faced similarly problems with sp-api five months ago, i had to contact the amz support to solved them, i hope this will help you...

good luck...

FatmaSedaOZYURT commented 2 years ago

I understand @CesarObedFL . I applied for support a few months ago. Unfortunately it doesn't not progress. But, thank you for answer. Your answer show me that is need to wait for amazon support...

fruch17 commented 2 years ago

@FatmaSedaOZYURT it doesn't work because my app was in review, once it was successfully published everything worked fine.

CesarObedFL commented 2 years ago

@FatmaSedaOZYURT yes it is a bit difficult to communicate with them, but they gave me the idea of using their Node SDK to connect to the SP-API, I had to develop a separate api with Node that I consume with PHP...

CesarObedFL commented 2 years ago

I have the same problem. Somebodies tell this problem may have been gotten in wrong request. But, when I viewed in this document , I see correctly request. My response is: { "errors": [ { "code": "InternalFailure", "message": "We encountered an internal error. Please try again.", "details": "" } ] } @fruch17 Did you find solution?

@fruch17 It is most likely that the error is because the signature of the requests does not match, so it is better to use the aws sdk for the sp-api

FatmaSedaOZYURT commented 2 years ago

I understand you and will check your responses on my app. Thank you all of responses.