Search code examples
amazon-mws

Amazon GetAuthToken c#


I am trying to call GetAuthToken from Amazon Web Services:

http://docs.developer.amazonservices.com/en_US/auth_token/AuthToken_GetAuthToken.html

I checked the C# client library and I cannot find GetAuthToken as a method. Has this been implemented? I tried to do a POST request without the library and it fails. Here is my request and response that I wrote manually:

Request

POST https://mws.amazonservices.com/ HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: mws.amazonservices.com
Content-Length: 238
Expect: 100-continue
Connection: Keep-Alive

AWSAccessKeyId=XX&Action=GetAuthToken&SellerId=XX&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2014-09-01T16%3A41%3A16Z&Version=2011-07-01&Signature=vRBxMEXAMPLES2y0FGPufG4u7WY2HqhcsYUW6IVI9%2BQ%3D

Response:

HTTP/1.1 404 Not Found
Date: Fri, 03 Oct 2014 17:14:53 GMT
Server: AmazonMWS
x-mws-request-id: 1a0bd189-d3e9-40b8-a55d-a420c9ed4805
x-mws-timestamp: 2014-10-03T17:14:54.195Z
x-mws-response-context:   VaGpX6JmTb+cM7WqwM6Fs8/E4oExbxl5c7li/EU0ho2j0/WpcYuG1XZSQzkuyrlr+kVTKBdKeG6F 3nwhM5s2gg==
Content-Type: text/xml
Content-Length: 368
Vary: User-Agent

<?xml version="1.0"?>
<ErrorResponse xmlns="https://mws.amazonservices.com/">
 <Error>
   <Type>Sender</Type>
   <Code>InvalidAddress</Code>
   <Message>Resource / is not found on this server. API Section is missing or you have provided an invalid operation name.</Message>
 </Error>
 <RequestID>1a0bd189-d3e9-40b8-a55d-a420c9ed4805</RequestID>
</ErrorResponse>

Solution

  • You have wrong ServiceURL setting. You can not have it as "mws.amazonservices.com", you have to specify proper ServiceURL according to the shop location. Use one of the following settings (taken from Amazon library samples) or check out more complete Developer Guide:

    // North America:
    $serviceUrl = "https://mws.amazonservices.com/Products/2011-10-01";
    
    // Europe
    $serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
    
    // Japan
    $serviceUrl = "https://mws.amazonservices.jp/Products/2011-10-01";
    
    // China
    $serviceUrl = "https://mws.amazonservices.com.cn/Products/2011-10-01";