PHP code example of myerp / myerp-php-api-client

1. Go to this page and download the library: Download myerp/myerp-php-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

myerp / myerp-php-api-client example snippets


use MyERP\MyERP;
$myERP = new MyERP('API_EMAIL', 'API_KEY');

// Get all the customers and leads
$customers = $myERP->customers()->findAll();
var_dump($customers);

// Get a specific customer/lead
$customer = $myERP->customers()->find(261367);
echo $customer['full_name'] . ' [id=#' . $customer['id'] . ']' . "\n";

// create a customer
$jane = [
    "type" => 2, //individual
    "status" => 1, //customer
    "first_name" => "Jane",
    "last_name" => "Doe",
    "email" => "[email protected]"
];
$jane = $myERP->customers()->save($jane);
echo $jane['full_name'] . ' created [id=#' . $jane['id'] . ', email=' . $jane['email'] . ']' . "\n";

// update some fields
$jane['email'] = '[email protected]';
$jane = $myERP->customers()->save($jane);
echo $jane['full_name'] . ' updated [id=#' . $jane['id'] . ', email=' . $jane['email'] . ']' . "\n";

// delete a customer
$byeJane = $myERP->customers()->delete(261368);
echo $byeJane['full_name'] . ' deleted [id=#' . $byeJane['id'] . ', email=' . $byeJane['email'] . ']' . "\n";

// catching errors
try {
  $response = $myERP->customers()->find(2613670);
  //....
} catch(APIException $e) {
  echo $e->getCode() . ' ' . $e->getMessage();
}
bash
php composer.phar