Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time
  REST API client PHP API-client in PHP for the web based software of Documentation can be viewed at API documentation.

##Getting started


  • PHP 5.4+

###Installation You can install the library via Composer by adding the following line to the require block of your composer.json file:

"": "1.1.*"

followed by running composer install.

###Setup You authenticate by simply adding your encrypted key_id and password and then you're good to go! Remember to use sandbox-mode in development. When ready to use in production you can just remove the third parameter.

Fakturan\Fakturan::setup('KEY_ID', 'PASSWORD', [
  'sandbox' => TRUE 

###Examples Retrieve all your products


Create a new product

$new_product = new Fakturan\Product();
$new_product->name = 'My new shiny product';
$new_product->unit = 'KG';
$new_product->price = 450;


Get a single product with id 54

$book = Fakturan\Product::find(54);

Get a single product via search

$product = Fakturan\Product::findBy(['product_code' => 2]);

Edit product

$book = Fakturan\Product::find(54);
$book->price = 25;

Delete a product

$product_to_be_deleted = Fakturan\Product::find(54);

Create an invoice

// Find your client
$client = Fakturan\Client::find(1);

$invoice = new Fakturan\Invoice();
$invoice->client_id = $client->id;
$invoice->date = date('Y-m-d');

// Find a product to use for templating
$product = Fakturan\Product::find(24);

// Add the product to the invoice. The second parameter can override the default values.
// It is used to set the amount and makes it possible to add a discount.
// See for possible attributes on rows.
$invoice->addRow($product, ['amount' => 5]);

// It is also possible to add rows without a preset product by sending an array instead:
$row = [
	'product_name' => 'My custom product',
	'unit' => 'PCS',
	'price' => 500,
	'amount' => 24

// Rows only consisting of text can also be added
$invoice->addRow(['text_row' => true, 'text' => 'Performed customizations: purple flames']);


###Errors The API will answer with different kinds of Exceptions depending on type of issue:

Fakturan\Error\AccessDenied       // Catches 401 (access denied) 
Fakturan\Error\ResourceNotFound   // Catches 404 (Resource not found). 
Fakturan\Error\ConnectionFailed   // Catches 407 (Connection to server failed).
Fakturan\Error\ResourceInvalid    // Catches 422 (Validation errors).
Fakturan\Error\ClientError        // Catches 400-499 (Client errors).
Fakturan\Error\ServerError        // Catches 500-599 (Server related issues).
Fakturan\Error\FakturanException  // Catches all of the above

As they all inherits from Fakturan\Error\FakturanException they can all be caught within one catch-block:

try {
	// Methods that sends a request to the server
catch(Fakturan\Error\FakturanException $e) 
  echo $e->getMessage();

When in production we recommend you to always use a try-catch block when using save, update_attributes and delete


PHP client for's API v2







No packages published