Rest API: Basic products
Basic products are those you later use in recipes or dishes. They are the building blocks from which the whole gastronomic offer is built. There are two types: Products/Ingredients â generic products you consume; they can be primary products or recipes you already buy pre-made. Tools/Materials â accessory products that are not consumed and are used to make or serve the recipes and dishes.
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: List all basic products
There are two calls:
GET:
https://app.tspoonlab.com/recipes/api/listIngredientsPaged
o
https://app.tspoonlab.com/recipes/api/listMaterialsPaged
You can pass the following request parameters:
start (int) the first row to return. Required.
rows (int), the number of rows. Required.
filter (String), a string to filter. Optional.
types (Array of String), an array with the ids of the categories to filter by (if you specify more than one, the product must have both). Optional.
marked (Boolean), returns only the marked ones. Optional.
hidden (Boolean), returns only the hidden ones. Optional.
used (Boolean), returns only products used in some recipe or dish. Optional.
notUsed (Boolean), returns only products not used in any recipe or dish. Optional.
withPrice (Boolean), returns only products with a price. Optional.
withNoPrice (Boolean), returns only products without a price. Optional.
withVendor (Boolean), returns only products with an associated supplier. Optional.
withNoVendor (Boolean), returns only products without an associated supplier.
withUnits also returns the units in the response.
withTypes returns the productâs categories.
withCost returns the productâs cost.
It returns:
retorna una List<EntityBaseImagesColor>
EntityBaseImagesColor {
String id;
String descr;
Long color;
short type;
String codi;
boolean hasData;
Short tag;
String tagComment;
}
Where:
id is the product identifier.
descr the product name.
color the colour associated with the product (only for a product/ingredient).
type takes value 0 for a product/ingredient and 1 for a tool/material.
codi the product code.
hasData indicates the product is used in some recipe or dish.
tag is null if the product has no mark, otherwise it takes the values:
Ok:1, MoreInfo:2, Error:3.
tagComment is the comment associated with the mark.
With the withUnits option it also returns:
String idUnit; // Unit id
String unit; // Unit description
With the withCost option it also returns:
Double cost; // Product cost
With the withTypes option it also returns:
List<EntityBaseDescr> listComponentTypes; // Basic categories
List<EntityBaseDescr> listComponentTypesOthers; // Property or cost categories
Across the two collections, all the productâs categories are sent, where EntityBaseDescr is:
EntityBaseDescr {
String id;
String descr;
}
Rest API: Create a product
There are two calls:
POST
https://app.tspoonlab.com/recipes/api/ingredient
https://app.tspoonlab.com/recipes/api/material
In the request body you specify:
class NewComponentBase {
String descr;
String altDescr;
String idUnit;
List<NewComponentType> listComponentTypes;
boolean includeInOrder;
boolean averageCost;
boolean fixedCost;
List<NewComponentStore> listStores;
Double cost;
Double minStock;
Double maxStock;
String codi;
Double caducity;
String barcode;
}
class NewComponentType {
String id;
}
class NewComponentStore {
String id;
}
descr is the product name.
altDescr is an alternative product name, usually a commercial one.
idUnit is the id of the productâs unit.
listComponentType is the list of categories to associate with the new product.
includeInOrder takes value true.
averageCost takes value false.
fixedCost takes value false.
listStores is the store or stores where the product will be stored.
cost the product cost expressed per unit.
minStock the productâs minimum stock.
maxStock the productâs maximum stock.
codi the product code.
caducity the productâs shelf-life days.
barcode the product barcode.
Rest API: Delete a product
There are two calls:
DELETE
https://app.tspoonlab.com/recipes/api/ingredient/{idComponent}
https://app.tspoonlab.com/recipes/api/material/{idComponent}
It returns nothing.
Rest API: Update a productâs cost
There are two calls:
PUT
https://app.tspoonlab.com/recipes/api/ingredient/{idComponent}/cost
https://app.tspoonlab.com/recipes/api/material/{idComponent}/cost
In the body you must specify the new cost.
{
Double value;
}
Once the cost is updated, it triggers a recalculation of the cost of the recipes and dishes that depend on it.
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.
