cURL

Any API call MUST always include these parameters:

  • clientCode - Your ERPLY account code (for example, "2881")
  • request - Name of the API function (getCustomers, verifyUser, getRelatedProducts etc).

Every API session must be authenticated with username, password and a call to verifyUser() (ie., a log-in procedure must be performed before other API functions can be called).

curl -X POST https://[your client code].erply.com/api/ \
-d "clientCode=[your client code]&username=[username]&password=[password]&request=verifyUser&sendContentType=1"

Upon successful login, this call will return a session key. All subsequent function calls must include sessionKey.

{
    "status":{
        "request":"verifyUser",
        "requestUnixTime":1370517868,
        "responseStatus":"ok",
        "errorCode":0,
        "generationTime":0.069983959197998,
        "recordsTotal":1,
        "recordsInResponse":1},
    "records":[
        {
            "userID":"6",
            "userName":"demo",
            "employeeID":"4",
            "employeeName":"Clara Smith",
            "groupID":"7",
            "groupName":"sales representatives",
            "sessionKey":"awdz94248de6f27afec27dbb2b0e1f83a5d969f594eb",
            "sessionLength":3600,
            "loginUrl":"https:\/\/s3.erply.com\/eng\/"
        }
    ]
}

Sessions have a default lifetime of 3600 seconds. If session expires, all subsequent API calls will be responded with an error code 1054 or 1055 (see the list of error codes). A new session can be started by calling verifyUser() with the correct credentials once more. It is also possible to refresh session regularly and call verifyUser() after regular intervals to prevent expiration.

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

Get-request example

We can call an API function using the following example:

curl -X POST https://[your client code].erply.com/api/ \
-d "clientCode=[your client code]&sessionKey=[session key]&request=getCustomerGroups&sendContentType=1"

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.

{
    "status":{
        "request":"getCustomerGroups",
        "requestUnixTime":1370518306,
        "responseStatus":"ok",
        "errorCode":0,
        "generationTime":0.0026619434356689,
        "recordsTotal":3,
        "recordsInResponse":3
    },
    "records":[
        {
            "clientGroupID":"17",
            "customerGroupID":"17",
            "parentID":"0",
            "name":"Loyal Customers",
            "pricelistID":"0",
            "added":"1283248838",
            "lastModified":"1306833659"
        },
        {
            "clientGroupID":"18",
            "customerGroupID":"18",
            "parentID":"0",
            "name":"One-time Customers",
            "pricelistID":"0",
            "added":"1283248848",
            "lastModified":"1306833655"
        },
        {
            "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():

curl -X POST https://[your client code].erply.com/api/ \
-d "clientCode=[your client code]&sessionKey=[session key]&request=saveCustomerGroup&name=Possible%20leads&sendContentType=1"

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

{
    "status":{
        "request":"saveCustomerGroup",
        "requestUnixTime":1370518630,
        "responseStatus":"ok",
        "errorCode":0,
        "generationTime":0.090903997421265,
        "recordsTotal":0,
        "recordsInResponse":0
    },
    "records":[
        {
            "id":31,
            "customerGroupID":31
        }
    ]
}

System returns the ID of newly-created item.

Delete-request example

Now, let's delete previously created customer group:

curl -X POST https://[your client code].erply.com/api/ \
-d "clientCode=[your client code]&sessionKey=[session key]&request=deleteCustomerGroup&customerGroupID=31&sendContentType=1"

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

{
    "status":{
        "request":"deleteCustomerGroup",
        "requestUnixTime":1370519147,
        "responseStatus":"ok",
        "errorCode":0,
        "generationTime":0.091126918792725,
        "recordsTotal":0,
        "recordsInResponse":0
    },
    "records":null
}