Recipes are a custom post type called wprm_recipe with regular taxonomies and custom fields associated with it. Because of that, they are accessible to the default WordPress endpoints for post types and taxonomies. You can learn more in the WordPress REST API Handbook.
Recipes in the REST API
Recipes are accessible through the WordPress REST API at the /wprm_recipe/ endpoint.
To read, send a GET request to the /wprm_recipe/<id> endpoint:
https://demo.wprecipemaker.com/wp-json/wp/v2/wprm_recipe/41
For creating a recipe, send a POST request to the /wprm_recipe/ endpoint and include that same kind of recipe array in the JSON body:
{
"recipe": {
"name": "My New REST API Recipe",
"summary": "Delicious and not created in a traditional way."
}
}
For updating you’d do the same, but send a PUT request to the correct /wprm_recipe/<id> endpoint.
Recipe Ratings in the REST API
Ratings are accessible through the WordPress REST API at the /wp-recipe-maker/v1/rating/ endpoint by any user with the moderate_comments capability.
To read a rating, send a GET request to the /rating/<id> endpoint:
https://bootstrapped.ventures/wp-json/wp-recipe-maker/v1/rating/123
For creating a rating, send a POST request to the /rating/ endpoint and include the rating array in the JSON body.
{
"rating": {
"date": "2018-04-17 12:57:39",
"comment_id": "22",
"user_id": "0",
"ip": "123.321.123.321",
"rating": "3"
}
}
The system will automatically update ratings if a particular IP/user/comment has already rated a particular recipe.
/rating/recipe/<id> and /rating/comment/<id> endpoints are available as well.
User Ratings Modal in the Premium Plugin
With the Premium, Pro and Elite bundle, you also have the /user-rating/<recipe_id> endpoint available, which can be used to create a rating with or without comment text, as if it came from the user ratings modal.
You can do a POST request to the /user-rating/<recipe_id> endpoint (make sure to change <recipe_id>
to the ID of the recipe you want to add a rating for) and pass along the following data:
{
"data": {
"post_id": "123",
"rating": "3"
"comment": "Optional Comment Text",
"name": "Optional Name",
"email": "Optional Email",
}
}
post_id
could be left blank as well, as it is only used if no parent post for the recipe is set. So only the rating
parameter is actually required. Take note that for the comment, name and email it will check whether those are required on the WP Recipe Maker > Settings > Star Ratings > User Ratings Requirements page.