Skip to main content

REST API: Products and materials 🧂

How to create, update, and delete ingredients/products and materials/tools

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:

  1. start (int) the first row to return. Required.

  2. rows (int), the number of rows. Required.

  3. filter (String), a string to filter. Optional.

  4. 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.

  5. marked (Boolean), returns only the marked ones. Optional.

  6. hidden (Boolean), returns only the hidden ones. Optional.

  7. used (Boolean), returns only products used in some recipe or dish. Optional.

  8. notUsed (Boolean), returns only products not used in any recipe or dish. Optional.

  9. withPrice (Boolean), returns only products with a price. Optional.

  10. withNoPrice (Boolean), returns only products without a price. Optional.

  11. withVendor (Boolean), returns only products with an associated supplier. Optional.

  12. withNoVendor (Boolean), returns only products without an associated supplier.

  13. withUnits also returns the units in the response.

  14. withTypes returns the product’s categories.

  15. 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.


Did this answer your question?