Contents
On this page

Replace Ingredients - Plugixa Recipe

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

Replace a recipe’s ingredient list with the one you send, in one request.

Needs the plugixa_recipe_edit capability, or WordPress’s edit_posts (Contributor and up).

Note. Every stored ingredient is deleted first, then the list you send is written. An empty or missing ingredients leaves the recipe with no ingredients: unlike Update Recipe, this route does not refuse that.

Request

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

Path parameters

Name Type Description
id integer The recipe’s id

Request body

Content type: application/json

Field Type Required Description
ingredients object[] Yes The new list. Each item takes the fields below.
ingredients[].name string No Ingredient name.
ingredients[].quantity string No As it should read: 2, 1 1/2, ½, 2-3, a pinch.
ingredients[].unit string No Unit.
ingredients[].notes string No A note, such as sifted.
ingredients[].group_name string No Section heading.
ingredients[].group_order, ingredients[].sort_order integer No Position of the group, then of the row. Default 0.
ingredients[].link_url string No A link for the ingredient.
ingredients[].is_optional boolean No Marks the ingredient optional.
ingredients[].substitution string No Suggested swap.

amount and amount_max are worked out from quantity; values sent for them are ignored. Rows are returned in group_order, then sort_order, so send positions when the order matters. The recipe’s modified_at is updated.

{
  "ingredients": [
    {
      "quantity": "2",
      "unit": "cups",
      "name": "flour",
      "sort_order": 0
    },
    {
      "quantity": "1 1/2",
      "unit": "cups",
      "name": "milk",
      "substitution": "oat milk",
      "sort_order": 1
    }
  ]
}

Responses

200 OK. data is the new list, read back.

{
  "success": true,
  "message": "",
  "data": [
    {
      "id": "101",
      "recipe_id": "12",
      "group_name": "",
      "group_order": "0",
      "sort_order": "0",
      "quantity": "2",
      "unit": "cups",
      "name": "flour",
      "notes": "",
      "link_url": "",
      "amount": "2.000",
      "amount_max": null,
      "is_optional": "0",
      "substitution": ""
    },
    {
      "id": "102",
      "recipe_id": "12",
      "group_name": "",
      "group_order": "0",
      "sort_order": "1",
      "quantity": "1 1/2",
      "unit": "cups",
      "name": "milk",
      "notes": "",
      "link_url": "",
      "amount": "1.500",
      "amount_max": null,
      "is_optional": "0",
      "substitution": "oat milk"
    }
  ]
}
Field Type Meaning
data[].id string The row’s id. Rows get new ids on every replace
data[].group_name string Section heading, such as For the batter. Empty when ungrouped
data[].group_order, data[].sort_order string Position of the group, then of the row in it
data[].quantity string The quantity as typed
data[].amount, data[].amount_max string|null The quantity as numbers (three decimals), amount_max for a range. null when the text is not a number
data[].unit, data[].name, data[].notes string Unit, ingredient name and a note
data[].link_url string Optional link for the ingredient
data[].is_optional string 1 or 0
data[].substitution string Suggested swap

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/ingredients" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"ingredients":[{"quantity":"2","unit":"cups","name":"flour","sort_order":0},{"quantity":"1 1/2","unit":"cups","name":"milk","sort_order":1}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/ingredients');
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([
        'ingredients' => [
            [
                'quantity'   => '2',
                'unit'       => 'cups',
                'name'       => 'flour',
                'sort_order' => 0,
            ],
            [
                'quantity'   => '1 1/2',
                'unit'       => 'cups',
                'name'       => 'milk',
                'sort_order' => 1,
            ],
        ],
    ]),
]);
$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/ingredients', {
  method: 'PUT',
  headers: {
    'Authorization': auth,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"ingredients": [{"quantity": "2", "unit": "cups", "name": "flour", "sort_order": 0}, {"quantity": "1 1/2", "unit": "cups", "name": "milk", "sort_order": 1}]}),
});
const { data } = await response.json();

Quick Links

Share