The API is currently in draft, use at own risk. This feature was last updated in 2014, no updates are being made pending the release of APIv2 (planned 2016).

Format

The API is based on a format of https://www.x4b.net/api/{Module}/{Method}

Arguments are supplied via GET or POST data.

Result is returned as JSON encoded data by default in the format of:

{response:"data"} or {error:"message",code:""}

Methods:

User

Module: User

Method: login

Arguments: user, pass

Server

Module: Server

Method: all

Arguments: none

Return: id, name, flag, available_proxies_v4, available_proxies_v6

Plan

Module: Plan

Method: all

Arguments: none

Return: id, name,gb.bill

Service

Module: Service

Method: all

Arguments: none

Return: id,type,data

If type is lease then data has the format of:

addr, server, plan

If type is unsupported then no data is provided as service is not compatible with the API

Module: Service

Method: delete

Arguments:

service - the ID of the service (int)

or

lease - the ID of the lease (int)

Module: Service

Method: usage

Arguments:

service - the ID of the service (int)

or

lease - the ID of the lease (int)

Return: used, unit

Port

Module: Port

Method: all

Arguments:

service- the ID of the service (int)

or

lease- the ID of the lease (int)

Return: array of id, from, to, addr, type, keepalive}

Module: Port

Method: add

Arguments:

service - the ID of the lease (int)

port - a structure as follows:

from, to, addr, type, keepalive

Return: id, from, to, addr, type, keepalive

Module: Port

Method: update

Arguments:

id - the ID of the port to update(int)

port - a structure of fields to update: to, addr, keepalive

Return: The resulting port data of id, from, to, addr, type, keepalive

Module: Port

Method: delete

Arguments:

service - the ID of the lease (int)

port[from] - the port from

port[domain] - the domain of the port to match (optional)

Return: the number of deleted ports

ACL (HTTP Only)

Module: ACL

Method: all

Arguments:

service- the ID of the lease (int)

port_id - the ID of the port (int)

Return: array of array of mode and mask

Module: ACL

Method: addAcl

Arguments:

service - the ID of the lease (int)

port_id - the ID of the port (int)

or

port_from - the "from" port (int)

acl[mask] - the ACL mask in CIDR format

acl[mode] - either allow or deny

order (optional) - an integer that describes the order where the highest number is the first rule. "start" will automatically insert at the start of the rule set (highest number) and is the default. end will insert a rule at the end (lowest number).

Return: status as a string

Module: ACL

Method: delete

Arguments:

service - the ID of the lease (int)

port_id - the ID of the port (int)

or

port_from - the "from" port (int)

mask - the ACL mask to delete

Return: the status as a string

Error Codes

Error code is optional, not all errors include a code. This list will be extended as needed.

  • Authentication Error

  • Out of Stock

  • Invalid Input

Example PHP code

<?php
class APICall
{
    protected $server;
    protected $ch;
    function __construct($server = null)
    {
        if ($server == null) {
            $server = 'https://www.x4b.net/api';
        }
        $this->server = $server;
        $this->ch     = curl_init();
    }
    function transfer_session_id()
    {
        curl_setopt($this->ch, CURLOPT_COOKIE, session_name() . '=' . $_COOKIE[session_name()]);
    }
    function call($module, $method, $argument, $type = 'ps')
    {
        $url = rtrim($this->server, '/') . '/' . $module . '/' . $method . '.' . $type . '?' . http_build_query($argument);
        $ch  = $this->ch;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $text = curl_exec($ch);
        $data = null;
        switch ($type) {
            case 'json':
                $data = json_decode($text);
                break;
            case 'ps':
                $data = unserialize($text);
                break;
        }
        if ($data === false) {
            throw new \Exception($text, -1);
        }
        if (isset($data['response'])) {
            return $data['response'];
        }
        if (isset($data['error'])) {
            throw new \Exception($data['error'], isset($data['code']) ? $data['code'] : 0);
        }
    }
}

Resellers and Bulk Users

Resellers and Bulk users may be given access to a unique key to reduce load on our servers from keeping their session logged in. This HOST_KEY parameter removes the need to explicitly login.