Rest API: Managing menus
In this article weâll see how to create, manage and delete menus.
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: Select a recipe center
The requests described in the following sections can be made for all recipe centers or for a single book. To retrieve the list of recipe centers and their identifiers, see the REST API: Recipe centers article. The recipe center identifier corresponds to the idRecipeCenter field of the UserRecipeCenter class. Once you have the identifier, add it to the headers so it is used on subsequent calls:
echo -n 'recipe:351583444167656299610202XXXXXXXXXXXX' >> rememberme.txt
So in your request headers you must specify the token returned by login, the cost center and the recipe center. Besides the rememberme token, you must send the cost center and the recipe center:
rememberme:aGVucnkudXBzYWxsLmRAZXXXXXXXXXXXXXXXXXX
recipe:351583444167656299610202XXXXXXXXXXXX
order:351583444167656299610202XXXXXXXXXXXX
If you want the calls to affect all recipe centers, specify all in recipe:
rememberme:aGVucnkudXBzYWxsLmRAZXXXXXXXXXXXXXXXXXX
recipe:all
order:351583444167656299610202XXXXXXXXXXXX
Rest API: Retrieve menus
To retrieve the menus:
GET:
https://app.tspoonlab.com/recipes/api/listMenusPagedEx
You can pass the following request parameters:
start (int), the first row to return. Required.
rows (int), the number of rows to return. Required.
filter (String), a string to filter. Optional.
It returns:
retorna una List<EntityBaseMenu>
EntityBaseMenu {
String id;
String descr;
String codi;
String altDescr;
String date;
Date dateGenerated;
boolean template;
Double pax;
}
Where:
id is the menu identifier.
descr is the menu name.
codi is the menu code.
altDescr is the menuâs alternative name.
date and dateGenerated are the menu date in text or Date format.
template indicates whether the menu is a template.
pax is the number of guests the menu is defined for.
Rest API: Retrieve a menu
To retrieve a menu:
GET:
https://app.tspoonlab.com/recipes/api/menu/ext/{idMenu}
idMenu is the menu identifier; it corresponds to the id field of EntityBaseMenu from the previous call. It returns:
MenuExt {
String id;
String descr;
String altDescr;
String codi;
boolean template;
Date date;
String dateFormatted;
Double pax;
private Double costMin;
private Double costMax;
private Double costAvg;
private List<MenuGroupExt> listMenuGroup;
}
id, descr, altDescr, codi, template, date, dateFormatted and pax take the same values as those obtained in EntityBaseMenu. costMin, costMax, costAvg are the menuâs minimum, maximum and average costs. listMenuGroup is the list of sections within the menu.
MenuGroupExt {
String id;
String descr;
String comment;
Double costMin;
Double costMax;
Double costAvg;
List<MenuGroupComponentExt> listMenuGroupComponent;
int typeMenuGroup;
Short numSelected;
}
id is the section identifier, descr the section description, comment the section comment. costMin, costMax, costAvg are the sectionâs minimum, maximum and average cost. In a menuâs sections you can have several options indicating whether all dishes are included or some must be selected. typeMenuGroup can take the following values:
short allIncluded = 0;
short chooseOne = 1;
short chooseMoreThanOne = 2;
short chooseMoreThanOneRepeated = 3;
allincluded: all the sectionâs dishes are served.
chooseOne: the customer chooses only one of the sectionâs dishes.
chooseMoreThanOne: the customer chooses the number of dishes from the section.
chooseMoreThanOneRepeated: the customer chooses the number of dishes from the section but may choose the same dish more than once.
numSelelected is the number of dishes to choose (only meaningful for chooseMoreThanOne or chooseMoreThanOneRepeated).
MenuGroupComponentExt {
String id;
String idComponent;
String descrComponent;
String idUnit;
String descrUnit;
String comment;
Double quantity;
Double cost;
}
Where:
id is the identifier of the dish within the section.
idComponent and descrComponent are the dish.
idUnit, descrUnit the unit the dish is expressed in.
comment the comment.
quantity the amount of the dish for the guests (Pax) defined in the menu.
cost the dishâs cost.
Rest API: Create a menu
To create a menu, make this call:
POST:
https://app.tspoonlab.com/recipes/api/menu/no/groups
Passing the following structure in the request body:
NewMenu {
String descr;
String altDescr;
String comment;
String codi;
Date date;
Boolean template;
Double pax;
}
Where:
descr is the menu name.
altDescr is the alternative name.
comment is the comment.
codi is the menu code.
date is the menu date (this field is optional).
template true if it is a template.
pax is the number of guests the menu is defined for.
It returns an idWrapper class with the identifier of the new menu created:
class IdWrapper {
String id;
}
Rest API: Add dishes to the created menu
Pass the idMenu obtained when creating the menu in the previous call:
PUT:
https://app.tspoonlab.com/recipes/api/menu/{idMenu}/components
First, create the sections:
class NewMenuGroupWrapper {
List<NewMenuGroup> menuGroups;
}
class NewMenuGroup {
String descr;
String comment;
short typeMenuGroup;
Short numSelected;
int position;
List<NewMenuGroupComponent> listMenuGroupComponent;
}
descr is the section name.
comment is the section comment.
typeMenuGroup takes the values:
short allIncluded = 0;
short chooseOne = 1;
short chooseMoreThanOne = 2;
short chooseMoreThanOneRepeated = 3;
numSelelected is the number of dishes to choose (only meaningful for chooseMoreThanOne or chooseMoreThanOneRepeated).
position indicates the order of the sections.
listMenuGroupComponent is the list of the sectionâs dishes.
class NewMenuGroupComponent {
String idComponent;
String idUnit;
Double quantity;
String comment;
int position;
}
Where: idComponent is the dish identifier, idUnit the unit identifier, quantity the amount of the dish for the guests (Pax) defined in the menu, comment the comment, and position the order of the dish within the section.
Rest API: Delete a menu
To delete a menu:
DELETE:
https://app.tspoonlab.com/recipes/api/menu/{idMenu}
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.
