PHP using SoapClient

Using the PHP SoapClient

Using the PHP SoapClient

Initialisation

$clearbooksUrl = 'https://secure.clearbooks.co.uk/';
 
$client = new SoapClient($clearbooksUrl.'api/wsdl/');
 
$client->__setSoapHeaders(array(
	new SoapHeader($clearbooksUrl . 'api/soap/',
		'authenticate', array('apiKey' => 'yourApiKey')),
));

createEntity

$entity = array(
	'company_name' => 'A new company',
	'contact_name' => 'Mr Contact Person',
	'address1' => 'address1',
	'town' => 'town',
	'county' => 'county',
	'postcode' => 'postcode',
	'email' => 'email@address.com',
	'phone1' => '01234 567890',
	'customer' => array(
		'default_account_code' => 1001001,
		'default_vat_rate' => 0.15,
		'default_credit_terms' => 30,
	),
	'supplier' => array(
		'default_account_code' => 1001001,
		'default_vat_rate' => 0.15,
		'default_credit_terms' => 30,
	),
);
 
$result = $client->createEntity($entity);
var_export($result);
 
// returns
18

updateEntity

$result = $client->updateEntity(18, $entity);
var_export($result);
 
// returns
18

deleteEntity

$result = $client->deleteEntity(18);
var_export($result);
 
// returns
null

listEntities

$result = $client->listEntities(array(
        'id' => array( 1, 2, 53),
	'type' => 'customer',
        'modifiedSince' => '2010-01-01 12:00:00',
	'offset' => 0,
));
var_dump($result);
 
// returns
array
 0 =>
    object(stdClass)[62]
      public 'supplier' =>
        object(stdClass)[63]
          public 'default_account_code' => int 30
          public 'default_vat_rate' => float 0.15
          public 'default_credit_terms' => int 30
      public 'id' => int 58
      public 'company_name' => string 'A new company' (length=13)
      public 'contact_name' => string 'Mr Contact Person' (length=17)
      public 'address1' => string 'address1' (length=8)
      public 'town' => string 'town' (length=4)
      public 'county' => string 'county' (length=6)
      public 'postcode' => string 'postcode' (length=8)
      public 'email' => string 'email@address.com' (length=17)
      public 'phone1' => string '01234 567890' (length=12)
      public 'building' => string '' (length=0)
      public 'address2' => string '' (length=0)
      public 'phone2' => string '' (length=0)
      public 'fax' => string '' (length=0)
      public 'website' => string '' (length=0)

createInvoice

$invoice = array(
	'dateCreated' => '2008-09-17',
	'dateDue' => '2008-10-17',
	'description' => 'My invoice',
	'reference' => 'trdfffffggt',
	'type' => 'purchases',
	'items' => array(
		array(
			'description' => 'Line item description',
			'unitPrice' => 1.44,
			'quantity' => 1,
			'type' => 1001001,
			'vatRate' => 0.15,
		),
	),
	'entityId' => 3,
	'project' => 1,
);
 
$result = $client->createInvoice($invoice);
var_dump($result);
 
// returns
object(stdClass)[2]
  public 'due' => float 1.66
  public 'invoice_id' => int 12
  public 'invoice_prefix' => string "INV"
  public 'invoice_number' => string "12"

voidInvoice

$invoice = array(
	'type' => 'purchases',
	'id' => 20,
);
 
$result = $client->voidInvoice($invoice);
var_export($result);
 
// returns
null

listInvoices

$result = $client->listInvoices(array(
        'id' => array(189),
	'ledger' => 'sales',
        'status' => '',
        'modifiedSince' => '2010-01-01 12:00:00',
	'offset' => 0,
));
 
var_dump($result);
 
// returns
 
array(1) {
  [0]=>
  object(stdClass)#7 (10) {
    ["items"]=> array(1) {
      [0]=>object(stdClass)#8 (6) {
        ["description"]=> string(32) "Advertising revenue for December"
        ["unitPrice"]=> float(3882.96)
        ["vat"]=> float(679.52)
        ["quantity"]=> float(1)
        ["type"]=> int(1001001)
        ["vatRate"]=> float(0.175)
      }
    }
    ["description"]=> string(32) "Advertising revenue for December"
    ["id"]=> int(189)
    ["reference"]=> string(0) ""
    ["dateCreated"]=> string(19) "2009-12-01 00:00:00"
    ["dateDue"]=> string(19) "2009-12-01 00:00:00"
    ["creditTerms"]=> int(0)
    ["project"]=> int(3)
    ["status"]=> string(4) "paid"
    ["type"]=> string(1) "S"
  }
}

createPayment

$payment = array(
	'type' => 'purchases',
	'project' => 1,
	'accountingDate' => '2008-09-17',
	'description' => 'My Payment',
	'amount' => 1,
	'entityId' => 3,
	'paymentMethod' => 5,
	'bankAccount' => 7502001,
	'invoices' => array(
		array(
			'id' => $invoiceId,
		),
	),
);
 
var_dump($client->createPayment($payment));
 
// returns
 
object(stdClass)[7]
  public 'payment_id' => int 102

listAccountCodes

$result = $client->listAccountCodes();
var_dump($result);
 
// returns
array
  0 =>
    object(stdClass)[6]
      public 'id' => int 4001001
      public 'account_name' => string 'Salaries' (length=8)
      public 'group_name' => string 'Administrative expenses' (length=23)
      public 'default_vat_rate' => string '0.00:Out' (length=8)
      public 'show_sales' => boolean false
      public 'show_purchases' => boolean true