Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get signature_v2_auth working for MWS Product API (sorry if this is not the appropriate place to ask) #16

Open
turqoisehat opened this issue Jun 19, 2017 · 6 comments
Labels

Comments

@turqoisehat
Copy link

turqoisehat commented Jun 19, 2017

Would love to get signature_v2_auth working for Amazon Product API (MWS, not product advertising).

The query is just a random UPC/EAN I picked to try and get my signatures working. I have set my secret key and access key etc using sys.setenv. I got that datetime straight out of the StringToSign produced by the MWS scratchpad.

I am doing this:
signature_v2_auth(datetime = '2017-06-19T22%3A19%3A12Z', verb = 'POST', service = 'mws.amazonservices.com', path = '/Products/2011-10-1', query_args = '5051892198158')

I am not getting the correct signature as a response. One lead as to what might be wrong, when using the Amazon Product API scratchpad, their example always wants SellerId and MarketplaceId and signature_v2_auth does not seem have any method of passing that information. They also want Action (in my case "ListMatchingProducts" however, there is also no place to pass this argument into signature_v2_auth.

Also, I am using signature_v2_auth because the scratchpad seems to default to version2 when I navigate to the Product API section.

Any help is appreciated. I have also tried to create signatures on my own using RCurl and RDigest, but failed. It would be useful if the documentation had better examples for version 4 as well, I would like to try version 4 but I'm not sure exactly what to put in for each argument such as canonical_headers and request_body.

@turqoisehat turqoisehat changed the title Can't get this working sorry if this is not the appropriate place to ask Can't get signature_v2_auth working for MWS Product API (sorry if this is not the appropriate place to ask) Jun 19, 2017
@leeper
Copy link
Member

leeper commented Jun 20, 2017

query_args should be a named list of the arguments you're trying to pass - SellerId, MarketplaceId, etc. See the documentation in ? signature_v2_auth for examples of this.

@turqoisehat
Copy link
Author

turqoisehat commented Jun 22, 2017

Excellent, thank you for clarifying that. So now I am trying this:

q1 <- 
list(Action = 'ListMatchingProducts',
	 MarketplaceID = 'XXXXXXXXXX',
	 SellerId = 'XXXXXXXXXXXXXX',
	 Query = '5051892198158',
         SignatureMethod = 'HmacSHA256',	 
         SignatureVersion = '2',
	 Version = '2011-10-01',
         Timestamp = TS,        ####This is currently an exact character string pasted from MWS scratchpad
	 AWSAccessKeyID = 'XXXXXXXXXXXXXXXXX') 

Signature <- signature_v2_auth(verb = 'POST', service = 'mws.amazonservices.com', path = '/Products/2011-10-1', query_args = q1, key = 'XXXXXXXXXXXXXXXXXXXXXXXX', secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')

Unfortunately the signature doesn't seem to match. I can't figure out where I went wrong this time based on the documentation.

The error I am receiving has changed though. Now I get:

"The AWS Access Key Id you provided does not exist in our records."

However, I doubled checked and my key is certainly correct. I am googling and checking stack overflow for this error now.

Edit: Have tried re-arranging the order of my ultimate URL due to a StackOverflow post indicating that the access key had to come first, also toggled GET / POST as some posts referenced that, no luck with either.

@leeper
Copy link
Member

leeper commented Jun 22, 2017

Can you link to the scratchpad that you're validating against?

@turqoisehat
Copy link
Author

turqoisehat commented Jun 29, 2017

https://mws.amazonservices.com/scratchpad/index.html

Sorry it took so long, been extraordinarily busy moving and starting a new job.

@turqoisehat
Copy link
Author

I should add I am using the "products" drop down and "ListMatchingProducts" as the operation.

@robbfitzsimmons
Copy link

Bumping this way-old thread as I've been getting this working (piece by piece) with several MWS API endpoints over the last few weeks, and it would be great to document a more robust way. @turqoisehat it's likely way too late to be helpful, but I have been able to get the ListMatchingProducts endpoint working with the following:

signature <- aws.signature::signature_v2_auth(format(Sys.time(),
                                                     format = "%Y-%m-%dT%H:%M:%SZ",
                                                     usetz = FALSE,
                                                     tz = "UTC"),
                                              query_args = list(Action = "ListMatchingProducts",
                                                                Version = "2011-10-01",
                                                                SellerId = Sys.getenv("MWS_SELLER_ID"),
                                                                MarketplaceId = Sys.getenv("MWS_MARKETPLACE_ID"),
                                                                Query = "$YOUR_SEARCH_GOES_HERE"),
                                              verb = "POST",
                                              service = "mws.amazonservices.com",
                                              path = stringr::str_c("/", "Products", "/", "2011-10-01"),
                                              key = Sys.getenv("AWS_ACCESS_KEY"),
                                              secret = Sys.getenv("AWS_SECRET_KEY"))

amazon_query <- httr::POST(url = "https://mws.amazonservices.com",
                           path = signature$Path,
                           query = list(AWSAccessKeyId = signature$Query$AWSAccessKeyId,
                                        Action = signature$Query$Action,
                                        SellerId = signature$Query$SellerId,
                                        SignatureVersion = signature$Query$SignatureVersion,
                                        Timestamp = signature$Query$Timestamp,
                                        Version = signature$Query$Version,
                                        Signature = signature$Signature,
                                        SignatureMethod = signature$Query$SignatureMethod,
                                        MarketplaceId = signature$Query$MarketplaceId,
                                        Query = signature$Query$Query))

query_results <- amazon_query %>% 
  httr::content(as = "parsed", type = "text/xml", encoding = "UTF-8") %>% 
  xml2::as_list()

However, endpoints that don't follow exactly this protocol (for example the Orders endpoint, which takes a list of one or more MarketplaceIds) will just simply not match the signature no matter what configuration I try.

If anyone has used the aws.signature library to write a reliable MWS wrapper, I'd love to see/use it, otherwise I'll hope to share it back when I finally get it working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants