175
rated 0 times
[
180]
[
5]
/ answers: 1 / hits: 23617
/ 6 Years ago, mon, july 2, 2018, 12:00:00
My api call requires me to pass the api key in the headers, but I'm getting error back from the api service {error:2424452,message:Invalid Api Key}
I know my api key is valid as I can make the same api call in Python just fine, example:
req = requests.Session()
req.headers.update({'x-api-key': 'my-api-key', 'X-Product': 'my-product-name'})
req.get(url)
But in javscript, the same call errors out. I believe I'm not setting the headers correctly or something?
var req = new XMLHttpRequest();
req.onreadystatechange=handleStateChange;
req.open(GET, url, true);
req.setRequestHeader(Host, api.domain.com, x-api-key, my-api-key, X-Product, my-product-name);
req.send();
- This
XMLHttpRequest
is not a browser call, rather in an application that supportXMLHttpRequest
.
More From » xmlhttprequest