Skip to main content

REST API: Units đŸ¶

How to retrieve and manage measurement units

Rest API: How units work

Units let you express, in a more natural way, the different formats used in recipes or purchase formats. For each unit you can define an equivalence. For example, you can state that 1 kg equals 1000 g. These equivalences must be universal and always hold true. What you must not define, for instance, is that 1 bottle equals 750 ml, since although that tends to be true for a bottle of wine, it is not for a soft drink or a spirit.

System login

To make calls to our APIs, the first thing you need is to authenticate through a login call. That call returns a token that you must then attach to every subsequent call.

This shell script shows how to authenticate using curl:

[email protected]
password=XXXXXXX

url=https://app.tspoonlab.com/recipes/api
authenticate='username='$username'&password='$password

echo -n 'rememberme:' > rememberme.txt
curl -v --data $authenticate $url/login >> rememberme.txt

On later calls, add the token received from the login call to your headers:

curl -X PUT -v -H "$(cat rememberme.txt)" $url/integration/llamada

Rest API: Select a cost center/restaurant

The requests described in the following sections refer to a cost center, which in most cases corresponds to a restaurant.

To retrieve the list of cost centers and their identifiers, see the REST API: Cost centers article.

The cost center identifier corresponds to the idOrderCenter field of the UserOrderCenter class. Once you have the identifier, add it to the headers so it is used on subsequent calls:

echo -n 'order:351583444167656299610202XXXXXXXXXXXX' >> rememberme.txt

So in your request headers you must specify both the token returned by login and the cost center identifier:

rememberme:aGVucnkudXBzYWxsLmRAZXXXXXXXXXXXXXXXXXX
order:351583444167656299610202XXXXXXXXXXXX

Rest API: Retrieve units

To retrieve the units:

https://app.tspoonlab.com/recipes/api/listUnitsPaged?filter=&rows=50&start=0

filter lets you filter by description; start and rows handle pagination. It returns a list of the units:

retorna un List<Unit>

class Unit {

private String id;
private String descr;
}

It returns the id and description (id, descr) of the unit.

Rest API: Retrieve a unit

To retrieve a unit:

GET https://app.tspoonlab.com/recipes/api/unit/{idUnit}/num/{numElements}

idUnit is the unit identifier obtained in the previous call. Besides the unit’s own information, it returns a list of products the unit is assigned to. numElements indicates how many you want to retrieve:

public class Unit extends EntityBaseDescr {

private String id;
private String descr;
private boolean defecte;
private boolean defectePlat;
private boolean defecteMenu;
private boolean defecteDetall;
private boolean defecteFormat;

private List<EntityBaseBool> listVendors;
private List<EntityBaseBool> listCustomers;
private List<EntityBaseComponent> listDetails;
private List<EntityBaseComponent> listComponents;
private long listVendorsCount;
private long listCustomersCount;
private long listDetailsCount;
private long listComponentsCount;
private List<UnitConversion> listConversions;

}

public class EntityBaseBool extends EntityBaseDescr {
private String id;
private String descr;
private boolean defecte;
}

public class EntityBaseComponent extends EntityBaseDescr {
private String id;
private String descr;
private Short type;
private Long color;
}

defecte indicates whether the unit is the default unit for weight.

defectePlat whether it is the default unit for dishes.

defecteMenu whether it is the default unit for menus.

defecteDetall whether it is the default unit for a recipe’s detail.

defecteFormat whether it is the default unit for a supplier’s purchase format.

listVendors and listCustomers indicate the suppliers or clients that reference this unit; EntityBaseBool holds the id and descr of those entities.

listDetails shows which recipe or dish lines contain this unit.

listComponents shows which recipes or dishes contain this unit.

In EntityBaseComponent, color is the product colour when it is an ingredient.

The type field indicates the product type:

  • 0 for ingredients / products

  • 1 for recipes

  • 2 for materials / tools

  • 3 for dishes

To retrieve more data associated with the unit:

GET https://app.tspoonlab.com/recipes/api/unit/{idUnit}/components/paged?filter=&rows=20&start=0

GET https://app.tspoonlab.com/recipes/api/unit/{idUnit}/details/paged?filter=&rows=20&start=0

GET https://app.tspoonlab.com/recipes/api/unit/{idUnit}/vendors/paged?filter=&rows=20&start=0

GET https://app.tspoonlab.com/recipes/api/unit/{idUnit}/customers/paged?filter=&rows=20&start=0

Rest API: Create a unit

To create a unit:

POST https://app.tspoonlab.com/recipes/api/unit

In the request body you pass:

public class NewUnit {

String descr;
boolean defecte;
Boolean defectePlat;
Boolean defecteMenu;
Boolean defecteDetall;
Boolean defecteFormat;
}

defecte is the default unit for weight (usually kg).

defectePlat the default unit for dishes (usually Rac).

defecteMenu the default unit for menus (usually Pax).

defecteDetail the default unit for a recipe or dish’s detail (usually kg or g).

defecteFormat the default unit for suppliers’ purchase formats.

Rest API: Delete a unit

To delete a unit:

DELETE https://app.tspoonlab.com/recipes/api/unit/{idUnit}

If the unit is being used in recipes, ingredients, dishes, menus, purchases or suppliers, it cannot be deleted.

Did you find this article helpful?

If you need further assistance, contact support by clicking the built-in Support Chat in the bottom-right corner of your screen.


Did this answer your question?