PHP-SDK to communicate with Billy (

2.1.0 2016-04-17 07:24 UTC

This package is auto-updated.

Last update: 2024-04-24 23:30:27 UTC


Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

PHP SDK for Billy API version 2 only from the Danish accounting program Billy.

Getting started

Before doing anything you should register yourself with Billy and get access credentials.



Simply add a dependency on lsolesen/billy-php-sdk to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a dependency on Billy PHP SDK 2.1:

    "require": {
        "lsolesen/billy-php-sdk": "2.1.*"

After running composer install, you can take advantage of Composer's autoloader in vendor/autoload.php.


Create a new client

First you should create a client instance that is authorized with api_key or provided by Billy.

use Billy\Client\Client as Billy_Client;
use Billy\Client\Request as Billy_Request;

try {
    $request = new Billy_Request($api_key);
    $client = new Billy_Client($request);
} catch (Exception $e) {

Create and update contact

use Billy\Contacts\ContactRepository;

try {
    // @todo: This will probably end up becoming an object of its own.
    $persons = array(
            'name' => $name,
            'email' => $email,
    $contact = new Contact();
        ->set('phone', $phone)
        ->set('street', $address['thoroughfare'])
        ->set('cityText', $address['locality'])
        ->set('stateText', $address['administrative_area'])
        ->set('zipcodeText', $address['postal_code'])
        ->set('contactNo', $profile_id)
        ->set('contactPersons', $persons);

    $repository = new ContactRepository($request);
    $created_contact = $repository->create($contact);

    $contact = $repository->getSingle($created_contact->getID());
} catch (Exception $e) {

Create and update product

use Billy\Products\ProductsRepository;

try {
    $prices = array();
    $prices[] = array(
        'currencyId' => 'DKK',
        'unitPrice' => '20.25',
    $product = new Product();
        ->set('prices', $prices);

    $repository = new ProductRepository($request);
    $created_product = $repository->create($product);

    $product = $repository->getSingle($created_product->getID());
} catch (Exception $e) {

Create an invoice

use Billy\Invoices\InvoicesRepository;

try {
    $invoice_line_items = array();

    $invoice_line = new InvoiceLine();
        ->set('priority', $priority)
        ->setDescription('My description')

    $invoice_line_items[] = $invoice_line->toArray();

    $new_invoice = new Billy_Invoice();
        ->set('lines', $invoice_line_items);

    $created_invoice = $repository->create($new_invoice);
    $billy_invoice_id = $created_invoice->getID();
} catch (Exception $e) {