MYOB is the leading accounting software in New Zealand and Australia. Most of the small and large bussiness companies use thier service to manage finance data. It has desktop and cloud base service.
Myob provide Accountright API to synchronize data with third party application. In this post we discuss How to Add Customer in Myob via API call using PHP. If you want that new registration and any lead data from your website direct save as a customer in Myob account. Than you can use this way to save new customer via api call.
First you need to authenticate MYOB api using API Credential. We also explained MYOB Authentication in our previous post.
Add Customer in MYOB Cloud Using API in PHP
For doing this fulfill api parameter request with required customer data. Check below code for this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php $username = 'Administrator'; $password = ''; $cftoken = base64_encode($username.':'.$password); $headers = array( 'Authorization: Bearer 'Access Token Value', 'x-myobapi-cftoken: '.$cftoken.'', 'x-myobapi-key: e7*********8', // Use API key Here 'x-myobapi-version: v2' ); $url = 'https://api.myob.com/accountright/'Company FIle ID'/Contact/Customer/'; $param_data = array( "LastName" => "Test", "FirstName" => "Customer", "IsIndividual" => "true", "IsActive" => "true", "SellingDetails" => array( "TaxCode" => array( "UID" => "3bd2fbea-54d7-4115-8030-b84360048465" ), "FreightTaxCode" => array( "UID" => "3bd2fbea-54d7-4115-8030-b84360048465" ), ) ); $param = json_encode($param_data); $newsession = curl_init($url); curl_setopt($newsession, CURLOPT_HTTPHEADER, $headers); //load all header data curl_setopt($newsession, CURLOPT_CUSTOMREQUEST, "POST"); //comment out this PUT line to change to a POST statement curl_setopt($newsession, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt($newsession, CURLOPT_POSTFIELDS, $param); curl_setopt($newsession, CURLOPT_SSL_VERIFYHOST, 0 ); curl_setopt($newsession, CURLOPT_RETURNTRANSFER, 1 ); $response = curl_exec($newsession); curl_close($newsession); ?> |
Using above MYOB api code new customer insert in MYOB Company file. Must update you api key and myob account access before to execute this script. If facing any issue, please contact us. Thanks
hi from where you get the Company FIle ID?
Hello Januka,
To get company id, need to call GET method for this request url “https://api.myob.com/accountright/?format=json”. Must pass authentication header in this call.
Hi,
Where I can get the company file id from which array? Thanks
Hi Vaqas,
To get company file Id, need to execute Accountright Info API call. Check this api method : http://developer.myob.com/api/accountright/v2/info/.
In this API method result, you will get all company file info belong to your Myob Account.
Thanks