Affiliate API
Table of Contents
Affiliate API
Authorization
Registration
Getting Autologin URL
Getting Leads
Getting Conversions
Getting Offers
Getting Locales
Code Samples
Registration
Get User’s IP
Client Autologin
Authorization
The affiliate API requires authorization by API key. Each API key is linked to only one affiliate - offer
combination and it must be passed using "Api-Key" header with each request. In addition, the API
requires IP whitelisting, so you need to provide your server’s IP, prior using the API.
API end point:
https://bnxapi.com
API key:
BADE6568-04CA-F538-F10F-288DA8E7B4EC
Registration
POST to /api/v2/leads
Parameters:
Parameter Description Mandatory
email string Yes
firstName string Yes
lastName string Yes
password string Yes
phone numeric Yes
areaCode numeric - /area code of the No
phone/
custom1 string No
custom2 string No
1
custom3 string No
custom4 string No
custom5 string No
comment string No
ip string No
offerName string No
offerWebsite string No
locale string No
Note: In case you need to record an unique identifier for each lead, please store
the “leadRequest->ID” value and use that to match the registration to the lead/conversions
responses.
Sample Request:
curl --location -g --request POST 'https://bnxapi.com/api/v2/leads' \
--header 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'firstName=Test' \
--data-urlencode 'lastName=Test' \
--data-urlencode 'email=test834u8t8u34t@abv.bg' \
--data-urlencode 'password=asd123ASD' \
--data-urlencode 'phone=7500012345' \
--data-urlencode 'ip=78.129.167.125' \
--data-urlencode 'custom1=' \
--data-urlencode 'custom2=' \
--data-urlencode 'custom3=' \
--data-urlencode 'custom4=' \
--data-urlencode 'custom5=' \
--data-urlencode 'comment=testcomment' \
--data-urlencode 'offerName=testOffer' \
--data-urlencode 'offerWebsite=offer.domain.com' \
--data-urlencode 'areaCode=44'
Sample Response:
{
"details": {
"leadRequest": {
"ID": "0KMrZQ9bkLyDAYxql5n2EQBZoeYkN7eJ1PogO6mBdajzvEAp3"
},
"advertiser": {
"name": { “name” },
"logo": "/uploads/broker_logos/268ec14ab6f9479a99b79aba3776117e.jpg"
},
"offer": {
"ID": "1",
"name": { “name“},
"hash": { “hash” }
},
2
"postbacks": [],
"redirect": {
"url": "https://example"
}
},
"message": null,
"server": {
"date": "2022-06-03 09:00:20",
"httpCode": 200,
"executionTime": 2.5061569213867188
}
}
Getting Autologin URL
GET to api/v2/brokers/login/details
Parameter Description
leadRequestID (required) Must be the leadRequestID from the registration response.
By default API returns you the autologin redirect url in response after successful lead request. This
method is used only if you need to get the actual autologin url after X time after the user has
registered.
Sample Request:
curl -X GET \
'https://bnxapi.com/api/v2/brokers/login/details?leadRequestID=PmaJKkVRQnyM9oYLpzj' \
-H 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC'
Sample Response:
"details": {
"url": "https://brokerurl.com",
"parameters": [],
"fragment": null,
"method": "GET"
},
"message": null,
"server": {
"date": "2022-06-20 07:56:11",
"httpCode": 200,
"executionTime": 1.0629150867462158
}
3
}
Getting Leads
GET to api/v2/leads
Parameter Description Mandatory
fromDate Date filter in YYYY-MM-DD HH:mm:ss format Yes
(ex. 2019-04-18 00:00:00)
toDate Date filter in YYYY-MM-DD HH:mm:ss format Yes
(ex. 2019-04-18 23:59:59)
fromTime Time filter in format HH:mm:ss (ex. 00:00:00) No
toTime Time filter in format HH:mm:ss (ex. 23:59:59) No
selectedDays Array with Days. Number from 1-7 (where 1 is No
Sunday, 2 is Monday…)
page Page number. Used for looping through pages. No
itemPerPage Items on each page. Maximum 1000. No
offerIDs Array Filter by offer IDs No
countryIDs Array Filter by country IDs No
Note: The “leadRequestIDEncoded” property uniquely identifies each lead (Take into consideration
that it is case sensitive). Use that to match leads records to conversions records.
Sample Request:
curl -X GET \
'https://bnxapi.com/api/v2/leads?fromDate=2019-04-18 00:00:00&toDate=2019-04-18
23:59:59&page=1&itemPerPage=1000' \
-H 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC'
Sample Response:
{
"items": [
{
"traderID": "XXX",
"campaignName": "",
"countryName": "",
"cityName": " ",
"leadRequestIDEncoded": "XXX",
"ip": "",
"signupDate": "2021-06-07 08:20:25",
"email": "",
"name": "",
"firstName": "",
"lastName": "",
"phone": "",
4
"customerID": "",
"countryCode": "GB",
"saleStatus": null,
"countryID":,
"cityID": "",
"campaignHash": "",
"FTDdate": null,
"depositAmount": null,
"localeName": "",
"localeCode": "",
"hasFTD": 0
}
],
"total": {
"items": "1"
},
"message": null,
"server": {
"date": "2021-06-20 12:45:41",
"httpCode": 200,
"executionTime": 0.5944440364837646
}
}
Getting Conversions
GET to api/v2/conversions
Parameter Description Mandatory
fromDate Date filter in YYYY-MM-DD HH:mm:ss format (ex. Yes
2019-04-18 00:00:00)
toDate Date filter in YYYY-MM-DD HH:mm:ss format (ex. Yes
2019-04-18 23:59:59)
fromTime Time filter in format HH:mm:ss (ex. 00:00:00) No
toTime Time filter in format HH:mm:ss (ex. 23:59:59) No
selectedDays Array with Days. Number from 1-7 (where 1 is No
Sunday, 2 is Monday…)
5
page Page number. Used for looping through pages. No
itemPerPage Items on each page. Maximum 1000. No
campaignIDs Array Filter by campaignIDs No
localeID Int Filter by localeID No
countryIDs Array Filter by brokerGroupIDs No
saleStatus String Filter by saleStatus No
Note: The “leadRequestIDEncoded” property uniquely identifies each lead. Use that to match leads
records to conversions records.
Sample Request:
curl -X GET \
'https://bnxapi.com/api/v2/conversions?fromDate=2019-04-18 00:00:00&toDate=2019-04-18
23:59:59&page=1&itemPerPage=1000' \
-H 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC'
Sample Response:
{
"items": [
{
"brokerAccountDepositID": "",
"amount": "0",
"currency": "USD",
"rateUSD": "1",
"depositDate": "2022-05-31 11:58:02",
"countryID": "",
"email": "",
"phone": "",
"signupDate": "2022-05-31 11:25:17",
"customerID": "",
"campaignName": "",
"countryName": "",
"firstName": "",
"lastName": "",
"countryCode": "",
"campaignHash": "",
"localeName": "",
"localeCode": ""
"leadRequestIDEncoded": ""
"qualified": ""
"qualifiedDate": ""
}
],
"total": {
6
"items": "1"
},
"message": null,
"server": {
"date": "2022-06-20 13:47:58",
"httpCode": 200,
"executionTime": 0.5250787734985352
}
}
Getting Offers
GET to /api/v2/offers
Parameter Description
search[name] Filter results by name.
page Page number. Used for looping through pages.
itemPerPage Items on each page. Maximum 1000.
Sample Request:
curl --location --request GET
'https://bnxapi.com/api/v2/offers?page=1&itemsPerPage=10&search%5Bname%5D=example' \
-H 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC'
Sample Response:
{
"data": {
"items": [
{
"id": 9852,
"name": "Offer Name",
"hash": "cxtd",
"catalogLogoPath":
"https://exampleOffer.com/ca692ec6d1e0b575d63.png",
"website": "https://exampleOffer.com/",
"commissions": [
{
"commissionEvent": "Conversion",
"countryName": "Singapore",
"commisionAmount": "$100"
},
],
"verticals":[
{
"ID": "811",
"name": "Offers"
}
7
]
},
],
"page": 1,
"totalItems": 126
},
"message": null,
"server": {
"date": "2021-06-09 14:38:48",
"httpCode": 200,
"executionTime": 0.2729299068450928
}
}
Getting Locales
GET to /api/v2/locales
Parameter Description Mandatory
search[name] Filter results by name. No
search[IDs] Filter results by ID. No
search[q] Filter results by name or code No
Sample Request:
curl --location --request GET 'https://bnxapi.com/api/v2/locales?search[q]=EN' \
-H 'Api-Key: BADE6568-04CA-F538-F10F-288DA8E7B4EC'
Sample Response:
{
"data": {
"items": [
{
"ID": 1,
"code": "af",
"name": "Afrikaans"
},...
]
},
"message": null,
"server": {
"date": "2022-06-20 14:03:53",
"httpCode": 200,
"executionTime": 0.4806358814239502
}
}
8
Code Samples
Registration
<?php
$endpoint = "https://bnxapi.com/api/v2/leads";
$api_key = "BADE6568-04CA-F538-F10F-288DA8E7B4EC";
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Api-Key: $api_key",
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
"firstName" => "Test",
"lastName" => "Test",
"email" => "test-random-email" . time() . "@mailinator.com",
"password" => "123456Asd",
"phone" => "2071566154",
"areaCode" => "44",
"ip" => "5.62.29.4", //you can use getUserIP() to get user's IP
"custom" => null, //custom fields for your own use
"custom1" => null, //custom fields for your own use
"custom2" => null, //custom fields for your own use
"custom3" => null, //custom fields for your own use
"custom4" => null, //custom fields for your own use
"custom5" => null, //custom fields for your own use
"comment" => null, //put here your comment
"offerName" => null, //put your offer name
"offerWebsite" => null, //put your domain
"currency" => "USD",
"locale" => "af_NA",
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
if (empty($output)) {
throw new \ErrorException("Can't make request");
}
$response = json_decode($output);
if (empty($response)) {
throw new \ErrorException("Can't parse request");
9
}
if (!in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), [200, 201])) {
throw new \ErrorException($response->messages[0]);
}
//SUCCESS - Your code here
echo "ok";
curl_close($ch);
} catch (\ErrorException $exc) {
http_response_code(400);
echo $exc->getMessage();
}
Get User’s IP
function getUserIP()
{
foreach (array('HTTP_LSWCDN_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED',
'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE |
FILTER_FLAG_NO_RES_RANGE) !== false) {
return $ip;
}
}
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
}
}
Client Autologin
<?php
//CHANGE THESE VARIABLES WITH THE DETAILS YOU RECEIVED FOR YOUR API
//DO NOT FORGET TO IMPLEMENT ERROR HANDLING BASED ON YOUR FLOW AND REQUIREMENTS
$endpoint = "https://bnxapi.com";
$leadRequestID = "";
$apiKey = "BADE6568-04CA-F538-F10F-288DA8E7B4EC";
$curl = curl_init();
10
//THIS CALL MUST BE DONE ON YOUR SERVER SIDE IN ORDER TO HIDE YOUR API KEY
curl_setopt_array($curl, array(
CURLOPT_URL => "$endpoint/api/v2/brokers/login/details?leadRequestID=$leadRequestID",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Api-Key: $apiKey",
),
));
$response = curl_exec($curl);
curl_close($curl);
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
//DO NOT DIRECTLY CALL THE API FROM JAVASCRIPT SINCE THIS WILL EXPOSE YOUR API KEY
var rawResponse = '<?php echo $response ?? ""; ?>';//WE INITIALIZE THE RESPONSE FROM THE
SERVER SIDE SCRIPT
if (rawResponse.length <= 0) {
throw new Error("Something went wrong...");//YOUR ERROR HANDLING HERE
}
var response = JSON.parse(rawResponse);
var url = response.data.url;
if (response.data.method == "POST") {//HANDLING THE POST METHOD
if (response.data.fragment) {
url = url + "#" + response.data.fragment;
}
var formJS = createElement("form", "", {
method: "POST",
action: url,
});
for (var key in response.data.parameters) {
var item = response.data.parameters[key];
var input = createElement('input', "", {
type: "hidden",
name: key,
value: item
});
appendChild(formJS, input);
}
11
document.body.appendChild(formJS);
formJS.submit();
} else {//HANDLING THE GET METHOD
var parameters = [];
for (var key in response.data.parameters) {
parameters.push(key + "=" + response.data.parameters[key]);
}
if (url.indexOf("?") === -1 && parameters.length > 0) {
url += "?";
}
if (parameters.length > 0) {
url += parameters.join("&");
}
if (response.data.fragment) {
url = url + "#" + response.data.fragment;
}
window.location.href = url;
}
//UTILITY FUNCTIONS TO CREATE THE HTML ELEMENTS
function createElement(tag, content, attributes) {
if (typeof content === "undefined") {
content = "";
}
if (typeof attributes === "undefined") {
attributes = [];
}
var newElement = document.createElement(tag);
newElement.innerHTML = content;
Object.keys(attributes).forEach(function (key) {
setAttribute(newElement, key, attributes[key]);
});
return newElement;
}
function setAttribute(selector, name, value) {
if (!value) {
value = "";
}
if (name) {
findElement(selector).forEach(function (element) {
element.setAttribute(name, value);
});
}
}
function appendChild(selector, html) {
12
if (!html) {
html = "";
}
findElement(selector).forEach(function (element) {
if (typeof html === "string") {
element.innerHTML = element.innerHTML + html;
} else if (typeof html === "object") {
element.appendChild(html);
}
});
}
function findElement(selector, element) {
if (typeof element === "undefined") {
element = document;
}
if (typeof selector === "string") {
return Array.prototype.slice.call(element.querySelectorAll(selector));
} else if (typeof selector instanceof Array) {
return selector;
} else if (typeof selector === "object") {
return [selector];
}
return [];
}
</script>
</body>
</html>
Last updated: 20.06.2022 Page /
13