function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MenteeMentee 

AWS Signature version 4 using Named Credentials callouts - how to add request parameters

Name- aws_WScallout
url - https://servicename.amazonaws.com
Identity Type - Named Principal
Authentication Protocol - AWS Signature Version 4
AWS Access Key ID - ******
AWS Secret Access Key - ********
AWS Region - us-east-1
AWS Server- executea
Generate Authorization Header - true 
 
String token ='abcdefghijkl'; (say)
 HttpRequest req = new HttpRequest();
 req.setEndpoint('callout:aws_WScallout/alpha/plan/5?Source=Ops&localen=NA');
 req.setMethod('GET');
 Http http = new Http();
 HTTPResponse res = http.send(req);
 while (res.getStatusCode() == 302) {
           res.setEndpoint(res.getHeader('Location'));
           res = new Http().send(req);
       }
 System.debug(res.getBody());

I have to add x-amz-access-token which I get programmatically from another webservice. without adding error I am getting.
DEBUG|{"message": "Missing required request parameters: [x-amz-access-token]"}
how should I add to this callout?
I tired doing this 
  • req.setHeader('x-amz-access-token', token); 
  • req.setHeader('Authorization', EncodingUtil.base64Encode( Blob.valueof('x-amz-access-token'+ token)));
  • req.setHeader('x-amz-access-token', EncodingUtil.base64Encode(Blob.valueof(token)));

I get this error
DEBUG|{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method..."}
MenteeMentee
Adding more info:
I used postman, where request works. I am setting the header with x-amz-access-token = token 
karimulla salesforcekarimulla salesforce
hi.. 
1)Please check whether the accesstoken is deserilized in the correct way from the programming, which may includes extra characters while deserilzing the data.
2)Use Advanced Rest client tool,(ARC) i has more features to see the exact error or exception.
3)Pass the values statically  using the anonymous window.
4)Give the header key and value in the correct format .

Finally , 1)please check weather the url provided for u  was exposed as global... 
Thank you..!
karimulla syed
MenteeMentee
hi karimulla syed

I tired all steps, still
System.HttpResponse[Status=Forbidden, StatusCode=403]