Authenticating your request
A signature is a 64-digit encrypted string that is crucial to the authorization process.
The signature code ensures and confirms that the information included in the request is genuine and hasn't been modified. The user must first generate a Signature Code and pass it through the login request based on which the system detects and authorizes the request. Any request with an invalid or unmatched Signature will be responded to as unauthorized.
Generating a Signature Code requires you to provide the Signature Key that is located in your Profile details under Company Credentials. Along with the request body, the Signature Key goes through encryption processes to finally get the Signature Code.
Below is the sample algorithm to generate a Signature Code:
const crypto = require("crypto");
const SIGNATURE_KEY = "JUYADZ3ZMrj8Bwdme2Pu8a4r"; // your signature key
// Your request body
const data = {
svAccServiceRQ: {
company: [
{
companyCode: "1810",
userName: "Muhammad_11",
account: [
{
bankCode: "11",
accountNum: "108057386290014",
corpId: "OSV0000062",
holderName: "Company Code 1810",
iban: "SA5330400108057386290014",
address: "riyadh",
currency: "SAR",
acERPcode: "ANB_1"
}
]
}
]
}
};
function generateSignature(reqBody) {
// Step 1: Convert request body to JSON string
const jsonString = JSON.stringify(reqBody);
// Step 2: Base64 encode the JSON string
const base64Data = Buffer.from(jsonString, "utf-8").toString("base64");
// Step 3: Append the SIGNATURE_KEY
const dataToHash = base64Data + SIGNATURE_KEY;
// Step 4: Generate SHA256 hash (hex encoded)
const signature = crypto.createHash("sha256").update(dataToHash).digest("hex");
return signature;
}
// Example usage
const signature = generateSignature(data);
console.log("Generated Signature:", signature);Here's a sample Signature Code:
❌ In case of Signature Key mismatch, an "Unauthorized or Invalid" response will be reflected
⚠️ If the process encounters a technical error, the system will respond to the request as "Technical/Internal/Server Error"