I am trying to fetch Groups in Salesforce Apex class. but I am getting Status code 401 "Status=Unauthorized" issue.
public class WorldCheckScreening_Sync_v2 { public WorldCheckScreening_Sync_v2() { string gatewayurl = '/v1/'; string gatewayhost = 'rms-world-check-one-api-pilot.thomsonreuters.com'; string apikey = 'XXXXXXXXXXXXXXXXXXXXXXXXX'; string apisecret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; string requestendpoint = 'https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/groups'; String formattedTimestamp = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z'); string dataToSign = '(request-target): get ' + gatewayurl + 'groups\n' + 'host: ' + gatewayhost + '\ndate: ' + formattedTimestamp; String strhmac = generateAuthHeader(dataToSign,apisecret); String authorisation = 'Signature keyId="' + apiKey + '",algorithm="hmac-sha256",headers="(request-target) host date",signature="' + strhmac + '"'; HttpRequest req = new HttpRequest(); req.setEndpoint(requestendpoint); req.setMethod('GET'); req.setHeader('Authorization',authorisation); req.setHeader('Cache-Control', 'no-cache'); Http http = new Http(); HTTPResponse res = http.send(req); system.debug(res); } public string generateAuthHeader(string dataToSign, string apisecret) { return EncodingUtil.base64Encode(Crypto.generateMac('HmacSHA256', Blob.valueOf(dataToSign), Blob.valueOf(apiSecret))); } }
Can you please help me here?