PHP

Erply API supports three types of requests - get, save and delete.

Get-request example

Using PHP API class, we can call an API function using the following example code:

<?php

session_start();

// include ERPLY API class
include("EAPI.class.php");

// Initialise class
$api = new EAPI();

// Configuration settings
$api->clientCode = [your client code];
$api->username = [username];
$api->password = [password];
$api->url = "https://".$api->clientCode.".erply.com/api/";

// Get client groups from API
// No input parameters are needed
$result = $api->sendRequest("getClientGroups", array());

// Default output format is JSON, so we'll decode it into a PHP array
$output = json_decode($result, true);

print "<pre>";
print_r($output);
print "</pre>";

?>

This call will give us the following result. A [responseStatus] tells whether the call succeeded or failed and [recordsTotal] tells how many records were returned.

Array
(
    [status] => Array
        (
            [request] => getCustomerGroups
            [requestUnixTime] => 1370507041
            [responseStatus] => ok
            [errorCode] => 0
            [generationTime] => 0.0026431083679199
            [recordsTotal] => 3
            [recordsInResponse] => 3
        )

    [records] => Array
        (
            [0] => Array
                (
                    [clientGroupID] => 17
                    [customerGroupID] => 17
                    [parentID] => 0
                    [name] => Loyal Customers
                    [pricelistID] => 0
                    [added] => 1283248838
                    [lastModified] => 1306833659
                )

            [1] => Array
                (
                    [clientGroupID] => 18
                    [customerGroupID] => 18
                    [parentID] => 0
                    [name] => One-time Customers
                    [pricelistID] => 0
                    [added] => 1283248848
                    [lastModified] => 1306833655
                )

            [2] => Array
                (
                    [clientGroupID] => 20
                    [customerGroupID] => 20
                    [parentID] => 0
                    [name] => Campaign sign-ups
                    [pricelistID] => 0
                    [added] => 1283248917
                    [lastModified] => 1306833695
                )

        )

)

Save-request example

Let us call a function that also needs an input parameter, saveCustomerGroup():

<?php

session_start();

// include ERPLY API class
include("EAPI.class.php");

// Initialise class
$api = new EAPI();

// Configuration settings
$api->clientCode = [your client code];
$api->username = [username];
$api->password = [password];
$api->url = "https://".$api->clientCode.".erply.com/api/";

// Create a new customer group
$inputParameters = array(
    "name" => "Possible leads",
);
$result = $api->sendRequest("saveCustomerGroup", $inputParameters);

// Default output format is JSON, so we'll decode it into a PHP array
$output = json_decode($result, true);

print "<pre>";
print_r($output);
print "</pre>";

?>

If the call is successful, the result will be as follows:

Array
(
    [status] => Array
        (
            [request] => saveCustomerGroup
            [requestUnixTime] => 1370508839
            [responseStatus] => ok
            [errorCode] => 0
            [generationTime] => 0.089351892471313
            [recordsTotal] => 0
            [recordsInResponse] => 0
        )

    [records] => Array
        (
            [0] => Array
                (
                    [id] => 30
                    [customerGroupID] => 30
                )

        )

)

System returns the ID of newly-created item.

Delete-request example

Now, let's delete previously created customer group:

<?php

session_start();

// include ERPLY API class
include("EAPI.class.php");

// Initialise class
$api = new EAPI();

// Configuration settings
$api->clientCode = [your client code];
$api->username = [username];
$api->password = [password];
$api->url = "https://".$api->clientCode.".erply.com/api/";

// Delete customer group
$inputParameters = array(
    "customerGroupID" => 30,
);
$result = $api->sendRequest("deleteCustomerGroup", $inputParameters);

// Default output format is JSON, so we'll decode it into a PHP array
$output = json_decode($result, true);

print "<pre>";
print_r($output);
print "</pre>";

?>

If the call is successful, the result will be as follows:

Array
(
    [status] => Array
        (
            [request] => deleteCustomerGroup
            [requestUnixTime] => 1370509344
            [responseStatus] => ok
            [errorCode] => 0
            [generationTime] => 0.095067977905273
            [recordsTotal] => 0
            [recordsInResponse] => 0
        )

    [records] => 
)