Contents
On this page

Update Nutrition - Plugixa Recipe

PUT /plugixa-recipe/v1/recipes/{id}/nutrition

Write a recipe’s nutrition row: created when the recipe has none, replaced when it has one.

Needs the plugixa_recipe_edit capability, or WordPress’s edit_posts (Contributor and up). The Nutrition app must be on.

Note. This is a full replace, not a merge. A value you leave out is stored as null and source goes back to manual. Send every value each time.

Request

PUT https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/nutrition

Path parameters

Name Type Description
id integer The recipe’s id

Request body

Content type: application/json

Field Type Required Description
serving_size string No What one serving is, such as 1 pancake.
calories, total_fat, saturated_fat, trans_fat, cholesterol, sodium, total_carbohydrate, dietary_fiber, total_sugars, protein, vitamin_a, vitamin_c, calcium, iron, potassium number No Per serving. Empty or omitted is stored as null.
source string No Where the values came from. Defaults to manual.

The plugin stores the numbers as given, with two decimals, and does not fix units. On the nutrition label, fats, carbohydrates, fibre, sugars and protein read as grams, and cholesterol, sodium, calcium, iron and potassium as milligrams.

{
  "serving_size": "1 pancake",
  "calories": 180,
  "total_fat": 6.5,
  "saturated_fat": 2,
  "cholesterol": 45,
  "sodium": 210,
  "total_carbohydrate": 26,
  "dietary_fiber": 1,
  "total_sugars": 6,
  "protein": 5
}

Responses

200 OK. data is the stored row, read back.

{
  "success": true,
  "message": "",
  "data": {
    "id": "7",
    "recipe_id": "12",
    "serving_size": "1 pancake",
    "calories": 180.0,
    "total_fat": 6.5,
    "saturated_fat": 2.0,
    "trans_fat": null,
    "cholesterol": 45.0,
    "sodium": 210.0,
    "total_carbohydrate": 26.0,
    "dietary_fiber": 1.0,
    "total_sugars": 6.0,
    "protein": 5.0,
    "vitamin_a": null,
    "vitamin_c": null,
    "calcium": null,
    "iron": null,
    "potassium": null,
    "source": "manual"
  }
}
Field Type Meaning
data object|null null when the recipe has no nutrition
data.serving_size string What one serving is
data.calories … data.potassium number|null The fifteen values, null when not set
data.source string Where the values came from, manual by default

Errors

Status Code When
404 rest_error No recipe with that id.

Plus the errors every endpoint can return.

Examples

curl -s -X PUT "https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/nutrition" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"serving_size":"1 pancake","calories":180,"total_fat":6.5,"protein":5}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/nutrition');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'serving_size' => '1 pancake',
        'calories'     => 180,
        'total_fat'    => 6.5,
        'protein'      => 5,
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const auth = 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`);
const response = await fetch('https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/nutrition', {
  method: 'PUT',
  headers: {
    'Authorization': auth,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"serving_size": "1 pancake", "calories": 180, "total_fat": 6.5, "protein": 5}),
});
const { data } = await response.json();

Quick Links

Share