amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
580 stars 730 forks source link

Cannot Migrate an Amazon MWS authorization to a SP-API #2094

Closed AlexDombrovsky closed 1 year ago

AlexDombrovsky commented 2 years ago

I downloaded the SP API code using Java SDK and created an AmazonSpApi client that calls GetAuthorizationCode(sellingPartnerId, developerId, mwsAuthToken) from the generated AuthorizationApi class. But I cannot change authentication from MWS to SP API because I cannot get AccessToken in the method below. RestClient.Execute() returns StatusCode: Unauthorized {\"error_description\":\"Client authentication failed\",\"error\":\"invalid_client\"}

public virtual string GetAccessToken()
        {
            LWAAccessTokenRequestMeta lwaAccessTokenRequestMeta = LWAAccessTokenRequestMetaBuilder.Build(LWAAuthorizationCredentials);
            var accessTokenRequest = new RestRequest(LWAAuthorizationCredentials.Endpoint.AbsolutePath, Method.POST);
            string jsonRequestBody = JsonConvert.SerializeObject(lwaAccessTokenRequestMeta);
            accessTokenRequest.AddParameter(JsonMediaType, jsonRequestBody, ParameterType.RequestBody);
            string accessToken;
            try
            {
                var response = RestClient.Execute(accessTokenRequest);
                if (!IsSuccessful(response))
                {
                    throw new IOException("Unsuccessful LWA token exchange", response.ErrorException);
                }
                JObject responseJson = JObject.Parse(response.Content);
                accessToken = responseJson.GetValue(AccessTokenKey).ToString();
            }
            catch (Exception e)
            {
                throw new SystemException("Error getting LWA Access Token", e);
            }

            return accessToken;
        }

Here are the LWAAuthorizationCredentials values I pass: {"grant_type":"client_credentials","refresh_token":null,"client_id":"AKIA**********","client_secret":"JBz4OS************","scope":"sellingpartnerapi::migration"}

Does anyone know how to fix this? My assumptions are:

  1. The ClientSecret and ClientID values are used every day in MWS authentication, so they are correct, but maybe for my purpose it should be other values that I should get from my amazon account? I can't check this right now because I don't have access. For this purpose I left the first few characters of ClientID and ClientSecret unhidden because I have seen that other developers' mwsAuthToken (ClientID) has the following pattern: mzn.mws.xxxxxxxxx-xxxx
mikeshimura commented 2 years ago

clientID and clientSecret should be as follows.

Please ref. followng document.

https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#step-3-configure-your-lwa-credentials

Mike Shimura

rohitdobariya commented 2 years ago

@AlexDombrovsky I have done migration before. Let me know if you need any support. happy to help you.

github-actions[bot] commented 1 year ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

github-actions[bot] commented 1 year ago

closed for inactivity