Rest API: How allergens work
When the account is created, tspoonlab provides a list of the 14 official allergens under the regulation in force in the European Union. Users can also create new allergens for more detailed management.
Allergens are assigned to ingredients/products. That assignment must be based on the technical sheets provided by the supplier, which must be kept on file to meet health requirements. In that assignment you can indicate whether it is an allergen or a trace.
Recipes and dishes always show the allergens resulting from a recalculation based on their ingredients. If the same allergen appears as a trace in one ingredient and as an allergen in another, the allergen is assigned directly.
In certain cases you may also want to assign traces to your final or intermediate products based on other productions carried out in the same station/premises. It is common, in environments working with flour or nuts, to assign these traces to the rest of the products.
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 the allergen list
To retrieve the list, make this call:
GET:
https://app.tspoonlab.com/recipes/api/listAllergiesPaged?filter=&rows=50&start=0
The filter parameter lets you filter by description, rows is the number of rows you want and start the first row to return. The request returns an array with the id and description of each allergen:
[
{
id:"194443382822263016755563050734447984070",
descr:"Altramuces"
},
{
id:"181691964862034253332266321442051901807",
descr:"Apio"
}
....
]
Rest API: Retrieve an allergen
To get the data, use the id obtained in the previous request and make this call:
GET:
https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}/components/num/{numChild}
The idAllergy parameter indicates the allergen to retrieve. The returned information also includes which base products (ingredients) and which recipes and dishes have that allergen. The numChild parameter indicates how many products with that allergen you want to return.
class Allergy {
String id;
String descr;
String comment;
List<AllergyComponent> listComponentBase;
List<AllergyComponent> listComponentComplex;
}
class AllergyComponent {
String id;
String descr;
String idComponent;
boolean traces;
private int type;
private Long color;
}
In AllergyComponent, id identifies the relationship between an allergen and a component. idComponent indicates the component this allergen is linked to, descr is the component name and traces indicates whether it is an allergen or a trace.
The type field indicates the product type:
0 for ingredients / products
1 for recipes
2 for materials / tools
3 for dishes
For ingredients/products, color indicates the assigned colour. If, for this allergen, you want to retrieve more base products or recipes and dishes, call:
GET https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}/base/{isBase}/components/paged?filter=&rows=20&start=0
Where the parameters filter, rows and start follow the criteria already explained. idAllergy is the allergen identifier and isBase indicates whether you want base products or recipes and dishes (takes the values true, false). It returns a list of AllergyComponent.
Rest API: Create an allergen
To create an allergen, call:
POST https://app.tspoonlab.com/recipes/api/allergy
Passing in the request body:
class NewAllergy {
String descr;
String comment;
}
descr and comment are the allergenâs description and comment.
Rest API: Modify an allergen
To modify an allergen, call:
PUT https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}
Passing in the request body:
class NewAllergy {
String descr;
String comment;
}
Rest API: Delete an allergen
To delete an allergen, call:
DELETE https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}
The allergen will be removed from all base products that have it assigned (as an allergen or as a trace) and from all recipes and dishes that use that ingredient.
Rest API: Assign an allergen to a product
Call:
POST
https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}/components/add
Passing in the request body:
class NewAllergyComponentsWrapper {
List<NewAllergyComponent> components;
}
public class NewAllergyComponent {
String id; // with null value
String idComponent;
boolean traces;
}
id is left with no value (null). idComponent is the product you want to assign the allergen to and traces indicates whether it is a trace. The request returns the list of all base products, recipes and dishes where the allergen has been added directly or indirectly.
class AllergyGroup {
List<AllergyComponent> listComponentBase;
List<AllergyComponent> listComponentComplex;
}
Rest API: Unassign an allergen from a product
To unassign, call:
POST
https://app.tspoonlab.com/recipes/api/allergy/{idAllergy}/components/remove
In the request body pass:
class NewAllergyComponentsWrapper {
List<DeleteAllergyComponent> components;
}
public class DeleteAllergyComponent {
String id;
}
The id corresponds to the identifier of the allergen with the component. It returns a list of all products where the allergen has been unassigned.
retorna un List<ComponentWithType>
class ComponentWithType {
String id;
String descr;
int type;
Long color;
}
id is the component/product identifier, descr the description. The type field indicates the product type:
0 for ingredients / products
1 for recipes
2 for materials / tools
3 for dishes
For ingredients/products, color indicates the assigned colour.
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.
