- Newest
- Most votes
- Most comments
As WangQinYang has said, the headers are in the wrong place. Should be in the options object, as per documentation:
async function updateItem() {
await del({
apiName: 'myRestApi',
path: 'items/1',
options: {
headers: {
Authorization: authToken
}
}
}).response;
}
https://docs.amplify.aws/gen1/javascript/build-a-backend/restapi/customize-authz/
Hi,
What I am getting back is an "unauthorized error". If I test the authorizer with that exact same authToken value I get a successful Response Likewise in postman, by adding the "Authorizer" header manually with the value being the idToken I have from the first line of code above
You mentioned here that you added the "Authorizer" header when using Postman, but your code uses the ”Authorization“ header.
headers: {'Authorization': authToken, 'Content-Type': 'application/json'}
You say you can get a normal response with Postman, I think the id_token should be in effect, and would suggest checking what the difference is between the Postman configuration and the code.
Relevant content
- asked 2 years ago

Apologies that was a typo in my post, I am sending "Authorization" in both Postman and my code. I have corrected the post.
I checked the amplify documentation about the use of tokens and found that headers should be in options, for example:
https://docs.amplify.aws/gen1/javascript/build-a-backend/restapi/customize-authz/
WangQinYang, yep that was the right answer, I noticed that yesterday and correct the placement of the headers and that sorted it. I had at looked the definition of the post method which has a "headers" parameter, and just assumed that they should go in there as an object. Rather silly mistake but glad it was something simple at least! I will update the post to reflect this as the correct answer