Frequently Asked Question
Overview
The InvokeARI API allows you to initiate calls through the Asterisk REST Interface (ARI). This API provides a way to originate calls with custom variables, contexts, and extensions.
API Endpoint
https://api.gen.uk/v2/invokeARI
Method
POST
Headers
- X-API-Key: Your API key for authentication
- Content-Type: application/x-www-form-urlencoded
- Accept: */* (or application/json)
Parameters
Parameter | Description | Required | Example |
---|---|---|---|
d | Destination endpoint (e.g., PJSIP/extension) | Yes | PJSIP/6001 |
c | Context to use for the call | Yes | from-internal |
e | Extension to dial or callback URL | Yes | 6002 |
t | Timeout in seconds (defaults to 30 if not specified) | No | 15 |
i | Caller ID to display | No | 01159339000 |
v | Variables to pass to the call in format "NAME=VALUE,NAME2=VALUE2" | No | VARIABLE=1234 |
ari | ARI endpoint URL | Yes | http://10.1.1.1:8088/ari |
ariuser | ARI username | Yes | MyAPIUsername |
aripass | ARI password | Yes | 345yq4e5hw45hw45w4h5w4h5 |
Response
The API returns a JSON object with the following structure:
{ "status": "success" or "fail", "response": { "success": true or false, "http_code": HTTP status code, "response": Decoded response from ARI, "curl_error": Any error message from cURL }, "debug": { // Debug information including transcript logs } }
Example Usage
JavaScript Example
const options = { method: 'post', headers: { Accept: '*/*', 'X-API-Key': 'YOUR_API_KEY', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ d: 'PJSIP/6001', c: 'from-internal', e: '6002', t: '15', i: '01159339000', v: 'SOMEVAR=1234', ari: 'http://10.1.1.1:8088/ari', ariuser: 'MyAPIUsername', aripass: '345yq4e5hw45hw45w4h5w4h5' }) }; fetch('https://api.gen.uk/v2/invokeARI', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Notes
You can use the context/extension to route originated calls into a dialplan for delivering messages, or other useful functions. For example our confirmcode dialplan, which reads out a confirmation code to the user can be used by calling context as 'confirmcode' and extension as 's'. This will call the 'destination' and read out the confirmation code provided in variables (CONFCODE=1 2 3 4). Alternatively, you could use this as a notification for a new ticket at the HelpDesk, or to alert someone on-call that a system has failed, the uses are endless.
Notes
- The API requires a valid API key for authentication.
- Variables (v parameter) should be formatted as comma-separated name=value pairs.
- The timeout parameter (t) defaults to 30 seconds if not specified.
- The API will return detailed debug information in the response, which can be useful for troubleshooting.
Error Handling
If the API call fails, the response will include a "status" field with the value "fail" and additional information about the error in the "response" field.