Using Postman
This guide will help you import the ONLIVE.SITE OpenAPI collection into Postman and configure automatic authentication for all endpoints.
Step 1: Import the OpenAPI Collection
-
Download the OpenAPI JSON file
- Access the ONLIVE.SITE API documentation
- Download the json-api.json file.
-
Import into Postman
- Open Postman
- Click the "Import" button in the upper left corner
- Drag and drop the JSON file or select it using the "Choose Files" button
- Postman will automatically detect that it's an OpenAPI file
- Click "Import" to confirm
-
Verify the import
- The collection will appear in your left sidebar with all endpoints organized
- Explore the folders to see all available endpoints
Step 2: Configure Collection Variables
Before setting up authentication, you need to add your credentials:
- Right-click on the imported collection and select "Edit"
- Go to the "Variables" tab
- Add the following variables:
| Variable | Type | Initial Value | Current Value |
|---|---|---|---|
accessKeyId | default | your-access-key-id | your-access-key-id |
secretKeyId | secret | your-secret-key | your-secret-key |
Mark secretKeyId as "secret" type so Postman will hide the value in the interface.
- Click "Save" to save the changes
Step 3: Configure the Pre-request Script
The pre-request script will run automatically before each request to calculate and add the authentication signature.
-
Open the collection settings
- Right-click on the collection
- Select "Edit"
-
Go to the "Pre-request Script" tab
-
Copy and paste the following script:
// Postman Pre-request Script for Onlive.site OpenAPI
// 1. Get your credentials from Postman collection variables
const accessKeyId = pm.collectionVariables.get("accessKeyId");
const secretKey = pm.collectionVariables.get("secretKeyId");
if (!accessKeyId || !secretKey) {
console.error("Please define 'accessKeyId' and 'secretKeyId' in your Postman collection variables.");
return;
}
// 2. Generate the Timestamp in YYYYMMDDTHHmmssZ format
function pad(number) {
return ("00" + number).slice(-2);
}
const now = new Date();
const timestamp = `${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}T${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}Z`;
// Add the date header to the request. Postman will replace it if it already exists.
pm.request.headers.upsert({
key: 'x-onlive-site-date',
value: timestamp
});
// 3. Create the "String to Sign"
const method = pm.request.method.toUpperCase();
const path = pm.request.url.getPath();
const queryParams = pm.request.url.query;
const body = pm.request.body ? pm.request.body.toString() : "";
// 3.1. Create the Canonical Headers
// Filter headers that start with 'x-onlive-site-', convert them to lowercase, and sort them.
const onliveHeaders = [];
pm.request.headers.all().forEach(header => {
const keyLower = header.key.toLowerCase();
if (keyLower.startsWith('x-onlive-site-')) {
onliveHeaders.push({
name: keyLower,
value: header.value.trim()
});
}
});
onliveHeaders.sort((a, b) => a.name.localeCompare(b.name));
const canonicalHeaders = onliveHeaders.map(h => `${h.name}:${h.value}`).join('\n');
// 3.2. Create the Canonical Query String
// Sort the URL parameters alphabetically.
const sortedQueryParams = [];
queryParams.each(param => {
// Ignore disabled parameters
if (param.disabled) return;
sortedQueryParams.push({
name: encodeURIComponent(param.key),
value: encodeURIComponent(param.value)
});
});
sortedQueryParams.sort((a, b) => a.name.localeCompare(b.name));
const canonicalQueryString = sortedQueryParams.map(p => `${p.name}=${p.value}`).join('&');
// 3.3. Create the Hashed Payload
// Hash the request body with SHA-256.
const hashedPayload = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);
// 3.4. Assemble the final "String to Sign"
const stringToSign = `${method}\n${canonicalHeaders}\n${path}\n${canonicalQueryString}\n${hashedPayload}`;
// For debugging, you can uncomment the following line to see the string to be signed
// console.log("String to Sign:", stringToSign);
// 4. Calculate the Signature
// Use HMAC-SHA256 with your Secret Key.
const signature = CryptoJS.HmacSHA256(stringToSign, secretKey).toString(CryptoJS.enc.Hex);
// 5. Add the Authorization Header
const authorizationHeader = `ONLIVESITE Credential=${accessKeyId}, Signature=${signature}`;
// Add the authorization header to the request.
pm.request.headers.upsert({
key: 'Authorization',
value: authorizationHeader
});
- Click "Save" to save the script
Step 4: Test the Configuration
- Select any endpoint from the collection
- Click "Send"
- Verify the response
- If the configuration is correct, you will receive a successful response (200, 201, etc.)
- If there's an authentication error (401), verify that your credentials are correct
Debugging
If you encounter authentication issues:
-
Open the Postman Console
- Go to View > Show Postman Console
- Or use the shortcut
Cmd+Alt+C(Mac) /Ctrl+Alt+C(Windows)
-
Uncomment the debug line in the script
console.log("String to Sign:", stringToSign); -
Send the request again and check the console to see the string being signed
-
Verify that your credentials are correct
- Access Key ID should be without additional spaces
- Secret Key should be without additional spaces
How the Script Works
The script automatically performs the following steps:
- Retrieves credentials from collection variables
- Generates a timestamp in UTC format (
YYYYMMDDTHHmmssZ) - Adds the header
x-onlive-site-datewith the timestamp - Creates a canonical string that includes:
- HTTP method
- Headers starting with
x-onlive-site-(alphabetically sorted) - Endpoint path
- Query parameters (alphabetically sorted)
- SHA-256 hash of the body
- Calculates the signature using HMAC-SHA256 with your Secret Key
- Adds the authorization header with the format:
ONLIVESITE Credential={accessKeyId}, Signature={signature}
The script runs automatically before each request in the collection, so you don't need to worry about manual authentication.
Important Notes
- ✅ The timestamp must be within 15 minutes of server time
- ✅ Make sure you have an internet connection to synchronize the time correctly
- ✅ Credentials are stored securely in collection variables
- ✅ The script uses the CryptoJS library that comes included with Postman
Next Steps
Once authentication is configured, you can:
- Explore all available endpoints in the collection
- Create and save request examples
- Organize requests into custom folders
- Export the collection with your settings to share with your team
For more information about authentication, see the authentication documentation.