Rest API: How categories work
Categories let you classify the different products in your system. There are separate classifications for:
Ingredients / products
Recipes / dishes
Materials / tools
Stores: Classifications on stores that make taking inventories easier. They can be assigned to any product type.
Productions: They let you group productions by category based on the order of execution or joint execution.
You can also mark categories with two extra flags:
A nutritional-property flag: For example, healthy or vegan.
A cost or income flag: Allows to link a product to a cost or income concept, for example food or drink.
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 categories
To retrieve the categories:
https://app.tspoonlab.com/recipes/api/listTypesPagedEx?filter=&rows=50&start=0&type=
filter lets you filter by description, start and rows handle pagination, and type lets you filter by category type. type can take the following values:
0 for ingredients / products.
1 for recipes.
2 for materials.tools.
3 for dishes.
5 for store categories.
8 for production categories.
It returns a list of the categories:
retorna un List<TypeComponent>
class TypeComponent {
private String id;
private String descr;
short type;
Long color;
String codi;
Boolean costBinded;
Boolean propertyBinded;
}
It returns the id and description (id, descr) and the type of that category (type). For type 0 (ingredients/products) the category can have an associated colour (color). If the category has been coded, it is returned in codi. If you indicate that the category is a cost or income one, the costBinded field is true (null or false means it is not a cost category). propertyBinded works the same way to indicate a nutritional-property category.
Rest API: Retrieve a category
To retrieve a category:
GET https://app.tspoonlab.com/recipes/api/type/{idFamily}/num/{numComponents}
idFamily is the category identifier obtained in the previous call. Besides the category’s own information, it returns a list of products the category is assigned to. numComponents indicates how many you want to retrieve.
It returns:
public class Type extends EntityBaseDescr {
String id;
String descr;
short type;
String color;
String codi;
Boolean costBinded;
Boolean propertyBinded;
List<ComponentType> listComponent;
}
class ComponentType {
String id;
String descr;
private int type;
private Long color;
private String idComponent;
}
Very similar to the previous call that lists categories, but here also indicating which products it has associated (only the first numComponents). In ComponentType, id is the identifier of that category with a product; idComponent and descr refer to the product. 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. To retrieve more components associated with the category:
GET https://app.tspoonlab.com/recipes/api/type/{idFamily}/components/paged?filter=&rows=20&start=0
Rest API: Create a category
To create a category:
POST
https://app.tspoonlab.com/recipes/api/type
Passing in the request body:
class NewType {
String descr;
String comment;
String codi;
short type;
String color;
String idParent;
Boolean costBinded;
Boolean propertyBinded;
}
Specifying the values indicated above. It returns the id of the new category wrapped in IdWrapper.
class IdWrapper {
String id;
}
Rest API: Modify a category
To modify a category:
PUT
https://app.tspoonlab.com/recipes/api/type/{idFamilia}
Passing in the request body the NewType class as indicated in "Create a category".
It returns no data; the HTTP request errors if a problem occurs.
Rest API: Delete a category
To delete a category:
DELETE
https://app.tspoonlab.com/recipes/api/type/{idFamilia}
It returns no data; the HTTP request errors if a problem occurs.
Rest API: Assign a category to a list of products
To assign a category to a list of products:
POST
https://app.tspoonlab.com/recipes/api/type/{idFamily}/components/add
In the request body, indicate the products to add:
class NewTypeComponentWrapper {
List<NewTypeComponent> components;
}
class NewTypeComponent {
String id; // Null when assigning
String idComponent;
}
id takes the value null. It returns the same components with their corresponding new id.
retorna List<ComponentType>
class ComponentType {
String id;
String descr;
int type;
Long color;
String idComponent;
}
Rest API: Unassign a category from a list of products
To unassign a category from a list of products:
POST
https://app.tspoonlab.com/recipes/api/type/{idFamily}/components/remove
In the request body, indicate the relationship to remove:
class NewTypeComponentWrapper {
List<NewTypeComponent> components;
}
class NewTypeComponent {
String id;
}
The id of the relationship you want to remove. It returns nothing.
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.
