Integration Preparation
About 437 wordsAbout 1 min
2026-03-27
Authorization
Please ensure that your authorization header follows the format below, including the required PHT prefix. This prefix ensures that the correct authorization rules are applied to your request.
Authorization: PHT apikey={{api_key}},signature={{signature}},timestamp={{timestamp}}
Description:
api_key: Application ID
shared_secret: Secret key
Authorization logic: Thesignatureis generated by concatenatingapi_key,shared_secret, and the current Unix timestamp, then applying a SHA-512 hash.
⚠️ Important: The
timestampvalue must be exactly the same as the one used to generate thesignature. If the values differ, the system will not be able to validate your signature, and the request will be rejected.
JAVA
public static String getAuthorization(String apiKey, String secret) {
Date date = new Date();
long timestamp = (date.getTime() / 1000);
String signature = null;
try
{
String toBeHashed = apiKey + secret + timestamp;
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] bytes = md.digest(toBeHashed.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte aByte : bytes)
{
sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(config.js));
}
signature = sb.toString();
} catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
String authHeaderValue = "PHT apikey=" + apiKey + ",signature=" + signature + ",timestamp=" + timestamp;
return authHeaderValue;
}.NET
public static string getAuthorization(string apiKey, string secret)
{
TimeSpan epochTicks = new TimeSpan(new DateTime(1970, 1, 1).Ticks);
TimeSpan unixTicks = new TimeSpan(DateTime.UtcNow.Ticks) - epochTicks;
double unixTime = (int)unixTicks.TotalSeconds;
var toBeHashed = apiKey + secret + unixTime;
var bytes = System.Text.Encoding.UTF8.GetBytes(toBeHashed);
string authHeaderValue = "";
using (var hash = System.Security.Cryptography.SHA512.Create())
{
var hashedInputBytes = hash.ComputeHash(bytes);
var hashedInputStringBuilder = new System.Text.StringBuilder(128);
foreach (var b in hashedInputBytes)
hashedInputStringBuilder.Append(b.ToString("X2"));
var signature = hashedInputStringBuilder.ToString();
authHeaderValue = "PHT apikey=" + apiKey + ",signature=" + signature + ",timestamp=" + unixTime;
}
return authHeaderValue;
}POSTMAN
// check preconditions
if (
!postman.getEnvironmentVariable("api_key") ||
!postman.getEnvironmentVariable("shared_secret")
) {
postman.setNextRequest(null);
console.log(
"The api_key or shared_secret environment variables have not been set",
);
// this method is not defined, so will give a clear error to user
// authentication_variables();
}
// setup authorization, checkin and checkout dates
postman.setGlobalVariable("authorization", getAuthorizationKey());
// postman.setGlobalVariable('checkin', getIsoDate(30));
// postman.setGlobalVariable('checkout', getIsoDate(32));
// postman.setGlobalVariable('arrival', getIsoTime(30));
function getAuthorizationKey() {
var timestamp = Math.floor(new Date().getTime() / 1000).toString();
return (
"PHT apikey=" +
postman.getEnvironmentVariable("api_key") +
",signature=" +
getSigSHA512(timestamp) +
",timestamp=" +
timestamp
);
}
function getSigSHA512(current_timestamp) {
var sig =
postman.getEnvironmentVariable("api_key") +
postman.getEnvironmentVariable("shared_secret") +
current_timestamp;
return CryptoJS.SHA512(sig).toString();
}
function getIsoTime(days_from_today) {
var MS_PER_DAY = 24 * 60 * 60 * 1000;
var date = new Date(new Date().getTime() + days_from_today * MS_PER_DAY);
return date.toISOString();
}
function getIsoDate(days_from_today) {
var date = new Date(getIsoTime(days_from_today));
return (
date.getFullYear() +
"-" +
pad(date.getMonth() + 1) +
"-" +
pad(date.getDate())
);
}
function pad(number) {
var r = String(number);
if (r.length === 1) {
r = "0" + r;
}
return r;
}