API

All types are accessible through the API using the following format for urls:

https://example.com/piranyaplatform/data/{type}.{format]

Example:

https://example.com/piranyaplatform/data/User.json

The following formats are supported:

Authentication

Authentication should be done using the Authorization HTTP header. Both Basic (username, password) and Bearer (access token) are supported.

While logged in you can create an access token using https://example.com/users/accesstoken?infinite=true

Request elevation

By default requests are made on behalf of the user that is authenticated. If no user is authenticated then the request is made as if it is viewed publicly and will thus only include public information.

Requests can be elevated by passing the elevation parameter (previously called mode in older versions of the platform).

The following values are supported and are ordered from least elevated to most elevated:

User elevation

This elevation is used when accessing information owned by the user, such as their home address, editing their profile or placing orders.

Department elevation

The Department elevation is used when executing a request on behalf of a department. This is useful when, for example, creating products that are sold by specific departments. The user does not need to be an admin but only needs permission to access the department and can use the Department elevation to tell the system that the product is created for and owned by a department and not the user itself.

Departments can be specified using the HTTP header Authorization-Department (value is a department id) or by passing the parameter for_department_id.

Admin elevation

This elevation is used when reading or writing data not owned by departments or when bypassing department restrictions as an administrator of a site.

Data may still be restricted in such a way that the administrator is only able to read or edit specific information but all of the commonly used data is usually available.

Generic parameters for all request types

Query

Example: https://example.com/piranyaplatform/data/User.json?api_version=3&depth=2

Returns the current user (since mode is user - the default). Most fields are hidden for brevity.

{
  "api_version": 3,
  "locale": "da",
  "data": [
    {
      "id": 16294,
      "created": "2020-12-15T08:47:53+01:00",
      "username": "test@piranya.dk",
      "email": "test@piranya.dk",
      "profile": {
        "first_name": "Test",
        "middle_name": null,
        "last_name": "Testsen",
        "email": "test@piranya.dk",
        "primary_phone": "+4512345678"
      }
    }
  ],
  "result": "ok"
}

Almost all fields can be used for filtering in the API so you could for exanple find users with a specific email address (as an admin) using:

https://example.com/piranyaplatform/data/User.json?api_version=3&depth=2&mode=admin&email=test@piranya.dk

Note that mode is admin since we are asking for details for other users

Insert

To create, for example, a new product we could perform the following POST request:

https://example.com/piranyaplatform/data/Product.json

Parameters:

{
  "data": [
    {
      "system_identifier": "SKU1234",
      ...
    }
  ]
}

Update

Update or PUT requests behave very similarly to POST requests above. The updated entity (with new values) should just be added within the data array but should of course have IDs or keys so the system knows which entity to update.

Delete

Deletes also have a similar format to POST and PUT requests, but only require entities to specify their key and not necessaryly all values for the fields.

E.g. a DELETE request with the payload below would delete the entity that has the ID 1234.

{
  "data": [
    {
      "id": 1234
    }
  ]
}