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
SonyaMSonyaM 

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.
SonyaMSonyaM
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
Headers:
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);