Simple PHP rest client

https://github.com/tcdent/php­restclient
Our examples use this library but any rest client is acceptable.

Rest API

Endpoint: api.promosoftware.co.uk/v2/{account}/{apikey}

Controllers

company contact quote sale invoice purchase product task
user
Returns JSON object (we only support JSON objects )
status info data
Example JSON returned object:
{“status”:{“result”:”ok”},”info”:{“method”:”add”,”docType”:”company”},”data”:{“ID”:”3″,”docNumber” :”Acme”}}

Company

Simple Methods GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/company /*Get all companies*/
api.promosoftware.co.uk/v2/{account}/{apikey}/company/1 //Get company with ID of 1
api.promosoftware.co.uk/v2/{account}/{apikey}/company/1/{method} //peforms method on this company with ID of 1

Methods:

quotes sales invoices purchases contacts
api.promosoftware.co.uk/v2/{account}/{apikey}/company/1/quotes // Get quotes for this company
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/company //Adds new company api.promosoftware.co.uk/v2/{account}/{apikey}/company/1 //Updates company with ID of 1

Create Company Example:

PHP
Using the library above.
));
$api=newRestClient(array(
’base_url’=>”http://api.promosoftware.co.uk/v2/{account}/{apikey}”
$addArray=array();
$addArray[‘CompanyName’]=”Acme”;
$addArray[‘CompanyAddr1’]=“10DowningStreet”;
$addArray[‘CompanyAddr2’]=“Westminster”;
$addArray[‘CompanyCity’]=“London”;
$addArray[‘CompanyPostcode’]=“L10NT”;
$result=$api->post(“company”,$addArray);
$json_object=json_decode($result->response);
$json_array=json_decode($result->response,true);

Response:

HTTP 201: Added with a json object as follows:
{“status”:{“result”:”ok”},”info”:{“method”:”add”,”docType”:”company”},”data”:{“ID”:”3″,”docNumber” :”Acme”}}

Contacts

Simple Methods GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/contact /*Get all contacts*/
api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1 //Get contact with ID of 1
Also..
api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1/{method} //peforms method on this contact with ID of 1

Methods:

quotes sales invoices purchases contacts
api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1/quotes // Get quotes for this contact
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/contact //Adds new contact api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1 //Updates contact with ID of 1

Create Contact Example:

PHP
Using the library above.
));
$api=newRestClient(array(
’base_url’=>”http://api.promosoftware.co.uk/v2/{account}/{apikey}”
$addArray=array();
$addArray[‘ContactFirstName’]=”Dave”;
$addArray[‘ContactLastName’]=“Davison”;
$addArray[‘ContactEmail’]=“dave@dave.com”;
$addArray[‘ContactSalutation’]=“Davo”;
$addArray[‘CompanyId’]=12;//INT
$result=$api->post(“contact”,$addArray);
json_decode($result->response);//returnsstdClassobject
json_decode($result->response,true);//returnsassocarray

Response:

HTTP 201: Added with a json object as follows:
{“status”:{“result”:”ok”},”info”:{“method”:”add”,”docType”:”contact”},”data”:{“ID”:”1″,”docNumber”:” Dave Davison”}}

Quotes

Simple Methods GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/quote /*Get all quotes*/
api.promosoftware.co.uk/v2/{account}/{apikey}/quote/1 //Get quote with ID of 1
Also..
api.promosoftware.co.uk/v2/{account}/{apikey}/quote/1/{method} //peforms method on this contact with ID of 1
Methods:
lines addline updateline
api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1/lines // Get product lines for this quote
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/quote //Adds new quote api.promosoftware.co.uk/v2/{account}/{apikey}/quote/1 //Updates quote with ID of 1

Create Quote Example:

PHP
Using the library above. (Add #link)
$addArray[‘QuoteDateEntered’]=’’;DATE//YYYY-dd-mm//2013-12-22LeaveBlankForToday
$addArray=array();
$addArray[‘QuoteNumber’]=”QU000001”;
//optionalandshouldbeuniqueleaveblankandthesystemaddasequentialnumber;
$addArray[‘QuoteCompanyId’]=’12’;
$addArray[‘QuoteCompanyName’]=’ACompany’;//TEXTOPT
$addArray[‘QuoteContactId’]=’18’;INT
$addArray[‘QuoteContactName’]=’AContact’;//TEXTOPT
$addArray[‘QuoteEnteredBy’]=”;
//INT-UserId//Default=1;
$addArray[‘QuoteProjectId’]=”;
$addArray[‘QuoteTitle’]=’QuoteTitle’;
$addArray[‘QuoteActive’]=”;
//INT0=Inactive/1=Active
$addArray[‘QuoteFollowUpDate’]=”;
//DATE//YYYY-dd-mm//2013-12-22
$addArray[‘QuoteFollowUpTime’]=”;
//TIMEhh:mm:ss//08:00:00;
$addArray[‘QuoteConverted’]=”;
//INT0=No/1=Yes
$addArray[‘QuoteConvertedDate’]=’’;//DATE//YYYY-dd-mm//2013-12-22Thisissetin
//INT //TEXT
conversion
default;
));
//TEXT //
$addArray[‘QuoteSubTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘QuoteTaxTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘QuoteGrandTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘CurrencyId’]=”;
//INT//SeeCurrencies-Leaveblankforyour
$addArray[‘ConversionRate’]=”;
//FLOAT//CurrencyIdisnotdefaultusethis
$addArray[‘QuoteSpecialInstructions’]=’’;//TEXT//SpecialInstructions
$addArray[‘QuoteLossReason’]=”);
$api=newRestClient(array(
’base_url’=>”http://api.promosoftware.co.uk/v2/{account}/{apikey}”

$result=$api->post(“quote”,$addArray);
echo json_decode($result->response);

Sales

Simple Methods GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/sale /*Get all sales*/
api.promosoftware.co.uk/v2/{account}/{apikey}/sale/1 //Get sale with ID of 1
Also..
api.promosoftware.co.uk/v2/{account}/{apikey}/sale/1/{method} //peforms method on this contact with ID of 1
Methods: lines
api.promosoftware.co.uk/v2/{account}/{apikey}/contact/1/lines // Get product lines for this sale
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/sale //Adds new sale api.promosoftware.co.uk/v2/{account}/{apikey}/sale/1 //Updates sale with ID of 1

Create sale Example:

PHP
Using the library above. (Add #link)
$addArray=array();
$addArray[‘SaleDateEntered’]=’’;DATE//YYYY-dd-mm//2013-12-22LeaveBlankForToday
$addArray[‘SaleCompanyId’]=’12’;
$addArray[‘SaleCompanyName’]=’ACompany’;//TEXT(OPT)EXPECTODDRESULTSIFYOUSET
THISTOACOMPANYNAMETHATDOESNTMATCHTHEID;
$addArray[‘SaleDeliveryCompanyId’]=’12’;//INT(OPT)DefaultSaleCompanyId;
$addArray[‘SaleDeliveryCompany’]=’ACompany’;//TEXT(OPT)EXPECTODDRESULTSIFYOUSET
THISTOACOMPANYNAMETHATDOESNTMATCHTHEID;
$addArray[‘SaleContactId’]=’22’;INT
$addArray[‘SaleContactName’]=’AContact’;//TEXT(OPT)
$addArray[‘SaleDeliveryContactId’]=’23’;INT
$addArray[‘SaleDeliveryContactName’]=’ADeliveryContact’;//TEXT(OPT)
$addArray[‘SaleEnteredBy’]=”;
//INT-UserId//Default=1;
$addArray[‘SaleProjectId’]=”;
$addArray[‘SaleTitle’]=’SalesOrderTitle’;
$addArray[‘SaleStatus’]=”;
//INT0=Inactive/1=Active//defaultis1;
$addArray[‘SaleSubTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘SaleTaxTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘SaleGrandTotal’]=”;
//FLOAT//Canbewrittenbutwillbeoverwritten
$addArray[‘CurrencyId’]=”;
//INT//SeeCurrencies-Leaveblankforyour
//INT
default;
$addArray[‘ConversionRate’]=”; //FLOAT//CurrencyIdisnotdefaultusethis
//TEXT

$addArray[‘SaleSpecialInstructions’]=’’;//TEXT//SpecialInstructions
));

You may add lines within this array , or add the lines afterwards see lines object for expected format.
$api=newRestClient(array(
’base_url’=>”http://api.promosoftware.co.uk/v2/{account}/{apikey}”
$result=$api->post(“sale”,$addArray);
print_r(json_decode($result->response));

Invoices

Simple Methods GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/invoice /*Get all invoices*/
api.promosoftware.co.uk/v2/{account}/{apikey}/invoice/1 //Get invoice with ID of 1
Also..
api.promosoftware.co.uk/v2/{account}/{apikey}/invoice/1/{method} //peforms method on this contact with ID of 1
Methods: lines
api.promosoftware.co.uk/v2/{account}/{apikey}/invoice/1/lines // Get product lines for this invoice
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/invoice //Adds new invoice api.promosoftware.co.uk/v2/{account}/{apikey}/invoice/1 //Updates invoice with ID of 1
Create invoice Example:

PHP
Using the library above. (Add #link)
$addArray = array();
$addArray[‘InvoiceDateEntered’]=’’; DATE // YYYY­dd­mm // 2013­12­22 Leave Blank For Today
$addArray[‘InvoiceCompanyId’]=’12’;
$addArray[‘InvoiceCompanyName’]=’A Company’; // TEXT (OPT) EXPECT ODD RESULTS IF YOU SET THIS TO A COMPANY NAME THAT DOESNT MATCH THE ID;
$addArray[‘InvoiceDeliveryCompanyId’]=’12’; // INT (OPT) Default InvoiceCompanyId; $addArray[‘InvoiceDeliveryCompany’]=’A Company’; // TEXT (OPT) EXPECT ODD RESULTS IF YOU SET THIS TO A COMPANY NAME THAT DOESNT MATCH THE ID;
$addArray[‘InvoiceContactId’]=’22’; INT $addArray[‘InvoiceContactName’]=’A Contact’; // TEXT (OPT)
$addArray[‘InvoiceDeliveryContactId’]=’23’; INT $addArray[‘InvoiceDeliveryContactName’]=’A Delivery Contact’; // TEXT (OPT)
$addArray[‘InvoiceEnteredBy’]=”; // INT ­ UserId // Default = 1; $addArray[‘InvoiceProjectId’]=”; // INT $addArray[‘InvoiceTitle’]=’Invoices Order Title’; // TEXT
$addArray[‘InvoiceStatus’]=”;// INT 0 = Inactive / 1 = Active // default is 1;
$addArray[‘InvoiceSubTotal’]=”;
$addArray[‘InvoiceTaxTotal’]=”;
$addArray[‘InvoiceGrandTotal’]=”;
$addArray[‘CurrencyId’] =”; //INT // See Currencies ­ Leave blank for your default; $addArray[‘ConversionRate’]=”; //FLOAT // CurrencyId is not default use this $addArray[‘InvoiceSpecialInstructions’]=’’; //TEXT // Special Instructions
//FLOAT // Can be written but will be overwritten //FLOAT // Can be written but will be overwritten //FLOAT //Can be written but will be overwritten
$api = new RestClient(array(
‘base_url’ => “http://api.promosoftware.co.uk/v2/{account}/{apikey}”
));
$result = $api­>post(“invoice”,$addArray); print_r( json_decode($result­>response) );

You may add lines within this array , or add the lines afterwards see lines object for expected format.

Purchase

Simple Methods

GET Request

api.promosoftware.co.uk/v2/{account}/{apikey}/purchase /*Get all purchases*/
api.promosoftware.co.uk/v2/{account}/{apikey}/purchase/1 //Get purchase with ID of 1
Also..
api.promosoftware.co.uk/v2/{account}/{apikey}/purchase/1/{method} //peforms method on this contact with ID of 1
Methods: lines
api.promosoftware.co.uk/v2/{account}/{apikey}/purchase/1/lines // Get product lines for this purchase
POST Request
api.promosoftware.co.uk/v2/{account}/{apikey}/purchase //Adds new purchase api.promosoftware.co.uk/v2/{account}/{apikey}/purchase/1 //Updates purchase with ID of 1

Create purchase Example:

PHP
Using the library above. (Add #link)
$addArray = array();
$addArray[‘PurchaseDateEntered’]=’’; DATE // YYYY­dd­mm // 2013­12­22 Leave Blank For Today
$addArray[‘PurchaseCompanyId’]=’12’;
$addArray[‘PurchaseCompanyName’]=’A Company’; // TEXT (OPT) EXPECT ODD RESULTS IF YOU SET THIS TO A COMPANY NAME THAT DOESNT MATCH THE ID;
$addArray[‘PurchaseDeliveryCompanyId’]=’12’; // INT (OPT) Default PurchaseCompanyId; $addArray[‘PurchaseDeliveryCompany’]=’A Company’; // TEXT (OPT) EXPECT ODD RESULTS IF YOU SET THIS TO A COMPANY NAME THAT DOESNT MATCH THE ID;
$addArray[‘PurchaseContactId’]=’22’; INT $addArray[‘PurchaseContactName’]=’A Contact’; // TEXT (OPT)
$addArray[‘PurchaseDeliveryContactId’]=’23’; INT $addArray[‘PurchaseDeliveryContactName’]=’A Delivery Contact’; // TEXT (OPT)
$addArray[‘PurchaseEnteredBy’]=”; // INT ­ UserId // Default = 1; $addArray[‘PurchaseProjectId’]=”; // INT $addArray[‘PurchaseTitle’]=’Purchases Order Title’; // TEXT
$addArray[‘PurchaseStatus’]=”; $addArray[‘PurchaseSubTotal’]=”; $addArray[‘PurchaseTaxTotal’]=”;
// INT 0 = Inactive / 1 = Active // default is 1; //FLOAT // Can be written but will be overwritten //FLOAT // Can be written but will be overwritten
$addArray[‘PurchaseGrandTotal’]=”;//FLOAT //Can be written but will be overwritten $addArray[‘CurrencyId’] =”; //INT // See Currencies ­ Leave blank for your default; $addArray[‘ConversionRate’]=”; //FLOAT // CurrencyId is not default use this $addArray[‘PurchaseSpecialInstructions’]=’’; //TEXT // Special Instructions
$api = new RestClient(array(
‘base_url’ => “http://api.promosoftware.co.uk/v2/{account}/{apikey}”
));
$result = $api­>post(“purchase”,$addArray); print_r( json_decode($result­>response) );

You may add lines within this array , or add the lines afterwards see lines object for expected format.

Product

$addFields[‘ProductSKU’]=””; // TEXT $addFields[‘ProductEnteredBy’]=””; // TEXT $addFields[‘ProductDateEntered’]=””; // TIMESTAMP $addFields[‘ProductTitle’]=””; // TEXT $addFields[‘ProductReference’]=””; // TEXT $addFields[‘ProductDescription’]=””; // TEXT $addFields[‘ProductNotes’]=””; // TEXT $addFields[‘ProductSupplierId’]=””; // INT $addFields[‘ProductSupplierName’]=””; // TEXT $addFields[‘ProductActive’]=””; // INT $addFields[‘ProductVatBuy’]=””; // TEXT $addFields[‘ProductVatSell’]=””; // TEXT $addFields[‘ProductNominalCodeBuy’]=””; // TEXT $addFields[‘ProductNominalCodeSell’]=””; // TEXT $addFields[‘ProductImage’]=””; // TEXT $addFields[‘ProductStockWebsite’]=””; // TEXT $addFields[‘ProductRating’]=””; // TEXT
$addFields[‘ProductStockLevelStart’]=””; // TEXT $addFields[‘ProductStockLevelCurrent’]=””; // TEXT $addFields[‘ProductSellPrice’]=””; // TEXT $addFields[‘ProductCostPrice’]=””; // TEXT $addFields[‘ProductSupplierCode’]=””; // TEXT $addFields[‘ProductMaterial’]=””; // TEXT $addFields[‘ProductDimensions’]=””; // TEXT $addFields[‘ProductBrandingArea’]=””; // TEXT $addFields[‘ProductFullText’]=””; // TEXT $addFields[‘ProductIsService’]=””; // INT $addFields[‘ProductDeliveryTime’]=””; // TEXT $addFields[‘ProductCustomField1’]=””; // TEXT $addFields[‘ProductCustomField2’]=””; // TEXT $addFields[‘ProductCustomField3’]=””; // TEXT $addFields[‘ProductCustomField4’]=””; // TEXT $addFields[‘ProductCustomField5’]=””; // TEXT $addFields[‘ProductCustomField6’]=””; // TEXT $addFields[‘ProductCustomField7’]=””; // TEXT $addFields[‘ProductCustomField8’]=””; // TEXT $addFields[‘ProductCustomField9’]=””; // TEXT $addFields[‘ProductCustomField10’]=””; // TEXT

Lines

Lines fields . These should be added through the relevant document controller quote,sale,invoice or purchase.

Note: if a LineQuantity is not set and LineProductSKU is not set the line will be treated as a descriptive line rather that a product or service line.

Example:

Add a line to a sale document; http://api.promosoftware.co.uk/v2/{account}/{apikey}/sale/2/addline
$addFields[‘VatSellCode’]=””; // FLOAT $addFields[‘VatBuyCode’]=””; // FLOAT $addFields[‘NominalBuyCode’]=””; // TEXT
$addFields[‘NominalSellCode’]=””; // TEXT $addFields[‘LineQuantity’]=””; // TEXT $addFields[‘LineProductSKU’]=””; // TEXT $addFields[‘LineProductId’]=””; // INT $addFields[‘LineDescription’]=””; // TEXT $addFields[‘LineSellPrice’]=””; // FLOAT
$addFields[‘LineCost’]=””; // FLOAT
$addFields[‘LineTotal’]=””; // FLOAT
$addFields[‘LineVatTotal’]=””; // FLOAT $addFields[‘LineCostTotal’]=””; // FLOAT $addFields[‘LineVatCostTotal’]=””; // FLOAT $addFields[‘LineColourId’]=””; // INT $addFields[‘LineColourName’]=””; // TEXT $addFields[‘LineSupplierId’]=””; // INT $addFields[‘LineSupplierCode’]=””; // TEXT $addFields[‘LineQuoteId’]=””; // INT ­ For quotelines; $addFields[‘LineSalesId’]=””; // INT­ For quotelines; $addFields[‘LineProjectId’]=””; // INT­ Related ProjectId / EnquiryId $addFields[‘LinePurchaseId’]=””; // INT­ For purchaselines; $addFields[‘LineInvoiceId’]=””; // INT­ For invoicelines; $addFields[‘LineBranding’]=””; // TEXT $addFields[‘LineMarkUp’]=””; // FLOAT $addFields[‘LineSortOrder’]=””; // INT

Task

$addArray[‘CompanyId’]=’22’; $addArray[‘ContactId’]=’12’; $addArray[‘ProjectId’]=’2’; $addArray[‘PurchaseId’]=”; $addArray[‘InvoiceId’]=”; $addArray[‘SaleId’]=”; $addArray[‘QuoteId’]=”; $addArray[‘TaskDue’] =”; $addArray[‘TaskContactType’]=”;
// INT ­ UserId // Default = 1; // INT
// INT
// INT
// INT
//DateTime
//FLOAT // CurrencyId is not default use this
// INT // INT
$addArray[‘TaskContactReason’]=’’; //TEXT // Special Instructions $addArray[‘Completed’]=”; // INT 0 / 1 1 = Complete Default 0 $addArray[‘TaskDateComplete’] =”; //DateTime $addArray[‘TaskUserId’]=”; // INT From UserId;
$api = new RestClient(array(
‘base_url’ => “http://api.promosoftware.co.uk/v2/{account}/{apikey}”
));
$result = $api­>post(“task”,$addArray); print_r( json_decode($result­>response) );

User

GET Requests:

api.promosoftware.co.uk/v2/{account}/{apikey}/user/1/ // retrieves user details with ID of 1
api.promosoftware.co.uk/v2/{account}/{apikey}/user/1/{method} //peforms method on this user with ID of 1

Methods: tasks

Example:
$api = new RestClient(array(
‘base_url’ => “http://api.promosoftware.co.uk/v2/{account}/{apikey}”
));
$result = $api­>get(“user/1”); Returns JSON Object

Leave A Response