My URL looks like this https://api.amazon.com/auth/o2/token?grant_type=authorization_code&code=ANafda..&client_id=amzn1.application-oa2-client.fafda....client_secret=ca3838ald...
I am constructing parameters and sending request like this:
httpRequest.onreadystatechange = receivedResponse; var grantType = 'grant_type=authorization_code'; var code = '&code=' + encodeURIComponent(responsecode); var clientIDparam = '&client_id=' + encodeURIComponent(clientId); //var redirectURI = '&redirect_uri=http://localhost:8000' var clientSecret = '&client_secret=' + encodeURIComponent('afda...'); var requestURI = 'https://api.amazon.com/auth/o2/token?' + grantType + code + clientIDparam + clientSecret; httpRequest.open('POST', requestURI, false); httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*"); httpRequest.send();
My request always fails with the following response:
{"error_description":"Malformed request","error":"invalid_request"}
HTTP 400
Not sure what is wrong. Could anyone help?
Thanks,
Vikram