Although nBill does not have a published API as yet, there are a number of built-in functions that you can use for integration purposes - either in a CRON job script, an event, or just by including the necessary nBill files in your own application. Some of the functions are only intended for internal use, but some could be useful for your own scripts in some circumstances - these functions are described below.

nbf_cms::$interop->create_user($name, $username, $password, $email)

This function creates a new CMS user record. The parameters are self-explanatory.

nbf_cms::$interop->change_user_group($user_id, $new_level)

This function changes the access level group of the supplied user ID. The value of $new_level should be the Group ID (gid) or role ID that you want to assign.

nbf_cms::$interop->send_email($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=NULL, $bcc=NULL, $attachment=NULL, $replyto=NULL, $replytoname=NULL)

This function will try to use the CMS's built-in mailing feature, if available, but if not it will use phpMailer (a 3rd party library included with nBill) to send an e-mail.

nbf_common::get_param($array, $key, $default_value = null, $no_escape = false, $encode_html = false, $allow_anything = false)

Retrieves a value from an array, optionally escaping any quote characters, optionally encoding any HTML, and defaulting to the supplied value if the array key does not exist. Use to sanitise user input before using in an SQL query.


This simply reads the date format from the global configuration settings. If you need to display a date somewhere, and wish to use the format selected by the nBill administrator, you can read it by calling this function.


Returns the IP address of the current user. Several methods are attempted, but it is possible that an empty string or NULL will be returned if the IP address cannot be detected.

nbf_common::fire_event($event_name, $params)

This will execute the code in any PHP files that are present in the corresponding folder. $params is an array of parameters that are passed to the event, as documented in the relevant readme file in the event folder. See the events topic for more information.

nbf_common::get_requested_page($full_url = false)

Detects the name of the page that was requested and return either the relative (default) or absolute (if $full_url flag is set to true) URL.


Redirects the page to the given URL.

For the following functions, you might need to 'include' a class file before calling them. The file that each function is defined in is shown below the function definition:

nbf_frontend::get_form_field_value($order_id, $field_name)

A useful function particularly for the 'order creation code' setting on the order form editor's advanced tab (but can be used anywhere you like), this will return the value entered on any one of your custom order form fields if you pass in the order ID and name of the field.

nbf_xref::get_countries($incl_eu_ww = false, $title_case = false)

Returns an array containing a complete list of countries, indexed by their ISO code. The first optional parameter allows you choose whether or not to include the two special entries: EU (European Union), and WW (Worldwide). The second optional parameter allows you to specify whether or not to convert the country names to title case.

nbf_date::get_next_payment_date($first, $start, $payment_frequency, $set_to_midnight = true)

Returns the next date that a payment would be due given the supplied start date and payment frequency. The date is returned as an integer representing a UNIX timestamp (number of seconds since 1st January 1970). The $first parameter requires that you enter the date the payment schedule was first set up.

This is to allow for cases where a monthly payment (for example) was initially taken on the last day of a month, some time in the past. If the last payment was taken on 28th February, and you want to retrieve the next payment date (so you pass in the 28th Feb as the start date), the date to be returned would need to be adjusted to the 31st, rather than the 28th of the next month - hence the need to pass in the first date as well as the start date for the period you want to calculate.

The $payment_frequency parameter should be passed in as a 2-letter payment frequency code. The optional $set_to_midnight flag specifies whether the timestamp should be forced to midnight (00:00h).

nbf_address::format_billing_address($address_1, $address_2, $address_3, $town, $state, $postcode, $country, $country_desc, $use_eu_format = false)

This function puts the various parts of an address together in the default format for the country it belongs to. For example, in the UK, addresses are usually presented in the format:

address line 1
address line 2
address line 3
county (state)

In Japan, they do it in reverse (country goes on the first line, and 1st line of address goes on the last line). In many EU countries, postcode, town and state appear on the same line (in that order). This function attempts to arrange the data in the right order for the country concerned. If you find invoices are producing wrongly formatted addresses for your country, you can amend this function, but please also contact us so we can change it for future releases.