API Overview
The Trackfinity REST API is accessible at http://<domain>/api/<endpoint>/<action>
where
/api/<endpoint>/<action>
is available only to admins<domain>
is your Trackfinity install domain name<endpoint>
is the endpoint that you are trying to access
Some of the endpoints do not require <action>
in the url.
Allowed Endpoints
Description | Method | Actions |
---|---|---|
Service | GET | /service/ping |
Report | GET | /report/profitloss |
Transaction | GET | /transaction/transaction_payout_preview |
Gaining Access to the REST API
In order to access Trackfinity's API your IP address must be in the ADMIN_API_ALLOWED_IPS list. You can add or remove IP addresses to this list via the Settings under the "Security" sub-section.
Allowed HTTP Request Methods
- GET
- POST
- PUT
- PATCH
Response Format
Trackfinity's API provides response in JSON format.
Response Status Codes
Code | Description |
---|---|
200 | API will return a '200' status and output the results of the API call |
400 | API will return a '400' status if an invalid or unsupported HTTP request is made |
404 | API will return a '404' status if an invalid parameter is sent, or if an HTTP request is sent to an invalid endpoint. |
405 | API will return a '405' status if an invalid HTTP request method is used |
Authentication
- The REST API uses HTTP Header Authentication.
- Each REST API request requires the Affiliate username and the Affiliate API key to be sent with the HTTP headers of the request.
- To retrieve your API key simply select it from the login table of your Trackfinity database or put in a support ticket and we can retrieve it for you.
- If you do not have an API key, you can set one by going to the Affiliates Admin and clicking the icon labeled, "Change API Key".
Note
Only full admin accounts are authorized to use the API and set an API key.
Required HTTP Headers
- api-key - affiliate api key
- api-username - affiliate user name
Note
The headers keys are NOT case sensitive.
Example Authentication
Authentication can be handled in various ways using different programming languages. Below are some complete example calls to the Ping endpoint with HTTP Header authentication.
php
<?php
$url = 'http://domain/api/ping'
$curl = curl_init();
$headers = array(
'api-key: 44b5498dbcb481a0d00b404c0169af62',
'api-username: productsupport'
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
$resp = curl_exec($curl);
//dumps an associative array representation of the json response
$output = json_decode($resp, true);
if($output !== NULL) {
//json was valid. Dump the decoded array
print_r($output);
}
else {
//invalid json, just dump the raw response
print_r($resp);
}
// Close request to clear up some resources
curl_close($curl);
?>
Python
This example requires pip and the request library which can be installed via pip by: 'pip install requests'
import requests
url = 'http://domain/api/ping'
headers = {
'api-key': '44b5498dbcb481a0d00b404c0169af62',
'api-username': 'productsupport'
}
params = {
'payvia_type_id': 1,
'rule_type': 'enabled'
}
res = requests.get(url, params=params, headers=headers)
print res.json()
node.js
This example requires npm and the request module which can be installed via npm by: 'npm install request'
var request = require('request');
var options = {
url: 'http://domain/api/ping',
method: 'GET',
json: true,
headers: {
'api-key': '44b5498dbcb481a0d00b404c0169af62',
'api-username': 'productsupport'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
else{
console.log(body);
}
}
request(options, callback);
curl
curl -X GET 'http://domain/api/ping' -H "api-key: 44b5498dbcb481a0d00b404c0169af62" -H "api-username: productsupport"
output: true