Flexbe API documentation
API (Application Programming Interface) allows you to get and change information about leads, clients, payments as well as to send information about events to your scripts.
API is used to send GET and POST requests to the URL which looks as follows:
http://{your_domain}/mod/api/?api_key={key}
api_key is used to identify all the requests to API. You can generate and change it in the Site panel.
The data is returned in the UTF-8 encoding, in JSON format. The content is stored in the “data” object.
- curl 'http://yourdomain.com/mod/api/?api_key=5xxxxxfc7103bde368b708b7f3ed95a004496740&method=checkConnection'
/* Response */
{"status":1} - echo file_get_contents(
'http://yourdomain.com/mod/api/'
.'?api_key=5xxxc7103bde368b708b7f3ed95a004496740'
.'&method=checkConnection'
);
// php.ini must have an option allow_url_fopen=On
/* Response */
{"status":1} - var request = require('request'); // npm install request request.post({ uri: 'http://yourdomain.com/mod/api/', form: {
api_key:'5xxxc7103bde368b708b7f3ed95a004496740',
method:'checkConnection'
}}, function(err, res, body) {
console.log(JSON.parse(body));
});
/* Response */
{"status":1}
Generating
Download an archive with examples of using API and event handlers.
Generate an HTTP API endpoint and an API key in the Settings — API.
Add URLs of your event handlers if needed.
- curl 'http://yourdomain.com/mod/api/?api_key=xxxxxxxxxx'
- // We initialize a class to work with API
require('flexbe_api.class.php');
$api_url = 'http://yourdomain.com/mod/api/';
$api_key = 'ed677c52dccc04a456f846ebe06849b551f53f20';
$flexbe = new flexbeAPI($api_url,$api_key);
// Connection check
if ( !$flexbe->checkConnection() ) {
print_r($flexbe->errors);
exit();
} - var request = require('request'); // npm install request
flexbeAPI = {
url:'http://yourdomain.com/mod/api/',
api_key:'ed677c52dccc04a456f846ebe06849b551f53f20',
// Call of API method
query:function(method, params, callbackFunc){
params.api_key = this.api_key;
params.method = method;
request.post({uri: this.api_url, form: params},
function(err, res, body) { try {
callbackFunc(JSON.parse(body));
} catch (error) { console.log(error); } });
},
};
Limits
You can receive up to 1000 leads per one request with getLeads method.
If you need to get more than 1000 leads, divide the call to API into several requests specifying start and count (pagination).
The maximum rate limit is 100 requests to API per minute.
Error codes
0 — Invalid acces key
1 — Request limit is exceeded
2 — Nonexistent method
- // Object with error information
error: {
code: 0,
msg: "Invalid api_key",
}
Methods
A method name is sent in the parameter &method=
http://{your_domain}/mod/api/?api_key={key}&method=getLeads
getLeads — getting
Leads are sorted by date of creation, from the last lead to the first one.
- curl 'http://yourdomain.com/mod/api/?api_key=xxxxx&method=getLeads&client_email=dev@flexbe.com'
- $leads_res = $flexbe->getLeads( array(
// Date of lead creation is more than a month ago
'date_from'=>strtotime('-1 month'),
// but less than today
'date_to'=>strtotime('today UTC'),
)); - flexbeAPI.query('getLeads', {
status:0 // new leads
}, function(result){
var leads = result.data.leads;
for(var id in leads){
var lead = leads[id];
console.log(lead);
}
});
status
0 — New
1 — Processed
2 — Fulfilled
10 — Cancelled
11 — Deleted
date_from
timestamp, lower limit to filter by date of lead creation
date_to
timestamp, upper limit to filter by date of lead creation
client_phone
Client's phone number, the exact match
is searched
client_email
Client's email, the exact match is searched
start
What position to start from. By default it is 0
count
Number of received leads. By default it is 25
Information returned about a lead:
id
Unique identifier
num
Lead number
time
Timestamp of lead creation time
status
Code — status code, name — status name
code — name:
0 — New
1 — Processed
2 — Fulfilled
10 — Cancelled
11 — Deleted
client
Array of information about a client:
name, phone number, email
note
Notes
form_name
Lead form name
form_data
Field values from a lead form
page
Page the lead was sent from
url — web address
name — name
utm
Values of UTM parameters, if used.
utm_source — source/advertising system
utm_campaign — campaign
utm_medium — medium type
utm_term — keyword term
utm_content — advertisement type
url — full page web address
pay
Information about an invoice/payment
id — unique invoice identifier
summ — amount due
status:
0 — Pending payment
1 — Payment in process
2 — Paid
3 — Payment error
time_create — timestamp of invoice creation
time_done — timestamp of invoice payment
desc — comment to a buyer
pay_link — link to the payment page
- // Restoration of a deleted lead
if($lead['status']==11){
$result = $flexbe->changeLead($lead['id'], array(
'status'=>10,
));
}
changeLead — changing
Fields to update a lead:
id*
Unique identifier of an edited lead
status
0 — New
1 — Processed
2 — Fulfilled
10 — Cancelled
11 — Deleted
client
Array of information about a client:
name, phone number, email
note
Notes
pay
Information about an invoice/payment
summ — amount due
status:
0 — Pending payment
1 — Payment in process
2 — Paid
3 — Payment error
desc — comment to a buyer
Web-hooks
Web-hook is a scrip to which the information about an event is sent.
For example, when a new lead is generated our server sends to your script information about it (POST method).
It allows getting information as quickly as possible and obviates the need
to track new leads/payments by regularly sending requests to API.
Main fields:
event
Event type
site
Information about a site
data
Information about an event (lead fields)
- // print_r($_REQUEST);
[event] => 'lead',
[site] => Array (
[id] => 174911 // account id
[sub_id] => 180023 // landing page (page group) id
[domain] => yourdomain.com
[name] => Landing page
)
[data] => Array (
[id] => 1414
[num] => 414
[time] => 1444215670
[status] => Array
(
[code] => 0
[name] => New
)
[client] => Array
(
// ... etc.
)
Lead event
It is triggered when a lead is created.
Information about the lead is sent to the webhook in the data field.
The information sent about a lead:
id
Unique identifier
num
Lead number
time
Timestamp of lead creation time
status
Code — status code, name — status name
code — name:
0 — New
1 — Processed
2 — Fulfilled
10 — Cancelled
11 — Deleted
client
Array of information about a client:
name, phone number, email
note
Notes
form_name
Lead form name
form_data
Field values from a lead form
page
Page the lead was sent from
url — web address
name — name
utm
Values of UTM parameters, if used.
utm_source — source/advertising system
utm_campaign — campaign
utm_medium — medium type
utm_term — keyword term
utm_content — advertisement type
url — full page web address
pay
Information about an invoice/payment
id — unique invoice identifier
summ — amount due
status (code / name):
0 — Pending payment
1 — Payment in process
2 — Paid
3 — Payment error
time_create — timestamp of invoice creation
time_done — timestamp of invoice payment
desc — comment to a buyer
test — Flag — test payment (through a test server)
Pay event
It is triggered when a notification about a payment or an error from a payment gateway (PayPal, etc.) is made.
The data of the lead event is repeated (see above). It contains updated information about the payment.
Help
If you have any further questions about API, contact dev@flexbe.com