request / request-promise

The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.
ISC License
4.77k stars 297 forks source link

Querystring or headers appear to be moving through redirects #335

Closed jakeleventhal closed 8 months ago

jakeleventhal commented 4 years ago

I am using the reports section of Amazon's Advertising API to try to generate and download reports.

I am able to generate the reports just fine using the POST request, but when I try to use the GET request to download a report, I get an error about using multiple headers. What's strange though, is that when I use Postman to make the same exact GET request with the same headers, the request works just fine and I am able to download the data.

Here is my code:

const response = await request.get({
    headers: {
      'Amazon-Advertising-API-ClientId': `${process.env.ADS_API_CLIENT_ID}`,
      'Amazon-Advertising-API-Scope': profileId,
      Authorization: `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    },
    url: `https://advertising-api.amazon.com/v2/${api}`
  });

Here is the same request in Postman (that works)

Screen Shot 2019-11-30 at 10 22 34 PM

And this is the error that I get when I try to make the request using request-promise:

(node:30398) UnhandledPromiseRejectionWarning: StatusCodeError: 400 - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>InvalidArgument</Code><Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>Bearer mysecretval</ArgumentValue><RequestId>somerequestid</RequestId><HostId>somehostid</HostId></Error>"

What's also strange is that I am able to make other GET requests to the Amazon Advertising API without any problems. After doing some digging, I found out that the report download API route uses a redirect. The error message seems to suggest that headers/some querystring is being set in the background. There needs to be a way to disable this.

jakeleventhal commented 4 years ago

Update: I tried doing the "Code" option on Postman and was reproducing the same error when exporting as Node.js but not with Python using the requests library. I was also able to make it work with the Go version.

hassanAwanAlvi commented 4 years ago

You are probably missing a few headers because here we have some custom headers. Try diagnosing it with Wireshark or Fiddler.

jakeleventhal commented 4 years ago

I am not missing headers. I tried it both manually and by exporting the request from Postman to Node.js. Like I said, the same request works with the Python version

robinchan2019 commented 4 years ago

This is my homepage https://www.upwork.com/freelancers/~01d9918b4a5391fe25 , I will help you.

TOPSinfo commented 4 years ago

We provide solutions around Amazon MWS and Advertising API's.

check www.esellerhub.com to know more about us.. We can do this easily..