+ Start a Discussion

salesforce rest api and javascript

I created javascript to test Rest APIs to an application from Postman. I am now trying to convert or rewrite it to be used in Salesforce to do the same. I am having a hard time in doing so. Any suggestions?
Prafull G.Prafull G.
You can check documentation available at Introduction to Apex REST (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_intro.htm) to build from scratch.

However if you are having any specific question or error then let us know and we would be happy to help.
It is really trying to rewrite the javascript into Apex and having difficulty in doing so to test from Salesforce instead of Postman.
I have been attempting to translating to Apex but I can't seem to get it right so I keep starting from scratch.

Get https://api.myapp.com/api/object
my pre-request Script in postman
Authorization set to no Auth
Authorization = myToken
Date = myDate

var CryptoJS = require("crypto-js");
var privateKey = " ";
var publicKey =  " ";
var uri = "/api/object/{value}";
var httpMethod = "get";
var now = new Date();
var rfc1123date = now.toUTCString();
pm.environment.set("myDate", rfc1123date);
var message = httpMethod + "|" + uri + "|" + rfc1123date.toLowerCase();
console.log(`message = ${message}`);
var hash = CryptoJS.HmacSHA256(message, privateKey).toString(CryptoJS.enc.Base64);
console.log(`hashInBase64 = ${hash}`);
var authMessage = publicKey + ":" + hash;
console.log(`authMessage = ${authMessage}`);
var token = btoa(authMessage);
console.log(`token = ${token}`);
pm.environment.set("myToken", token);