Running x-hoppers Parameterized Actions via API
This guide explains how to run parameterized actions using x-hoppers API, allowing you to insert dynamic values into predefined variables in a broadcast message. You can trigger actions using either Curl or Node.js's native fetch
API.
Prerequisites
- (For Node.js only) Ensure that Node.js (v18 or higher) is installed, as it includes the native
fetch
API.
Step 1: Prepare the URL for Direct Action Execution
1.1 Prepare the QR code
Before executing the action, refer to the following guide to prepare your QR code:
How to generate and manage QR codes.
In the text of the broadcast message in WMS, you need to add names of the required variable(s):
Example:
Customer {{Parameter1}}
requires assistance at till point 1
1.2 Copy the QR code's URL
Copy the QR code's URL to share or distribute. For example:
https://notification.x-hoppers.com/b33idD20-0000-0000-8999-39fb00005585
.
1.3 Modify the URL Format Manually adjust the URL as follows: Original: https://notification.x-hoppers.com/b33idD20-0000-0000-8999-38Bb00005585 Modified: https://xhop-webhook.wildix.com/v1/action/b33idD20-0000-0000-8999-38Bb00005585
Example: Using Curl
The following query demonstrates how to use the curl
function to run a parameterized action.
curl --location 'https://xhop-webhook.wildix.com/v1/action/b33idD20-0000-0000-8999-38Bb00005585' \
--header 'Content-Type: application/json' \
--data '{
"parameters": {
"Parameter1": "SomeText",
"Parameter2": "SomeText2"
}
}'
Example: Using Node.js fetch
The following code demonstrates how to use the fetch
function to run a parameterized action.
// Replace these with your actual ID (e.g. https://xhop-webhook.wildix.com/v1/action/{id})
const URL = 'Prepared URL (e.g. https://xhop-webhook.wildix.com/v1/action/b33idD20-0000-0000-8999-38Bb00005585)';
const requestBody = {
parameters: {
Parameter1: 'SomeText1',
Parameter2: 'SomeText2',
},
};
fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
})
.then(async (response) => {
if (!response.ok) {
throw new Error(`Request failed with status: ${response.status} - ${response.statusText}`);
}
console.log('Response data:', await response.json());
})
.catch((error) => {
console.error('Error occurred:', error);
});
Expected Response
{"message":"Success","redirectUrl":"","success":true}
Notes
- In the WMS admin panel, as described
in How to generate and manage QR codes,
the fields
broadcastMessage
andpbx
accept only letters and specific symbols, including:0-9!?., -–{}
. - In POST request, the action body parameters can only include letters and specific symbols, such as:
0-9!?., -–
.