Contents
On this page

Replace Instructions - Plugixa Recipe

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

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

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

Note. Every stored step is deleted first, then the list you send is written. An empty or missing instructions leaves the recipe with no steps.

Request

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

Path parameters

Name Type Description
id integer The recipe’s id

Request body

Content type: application/json

Field Type Required Description
instructions object[]|string[] Yes The new list. A bare string is a step with only text.
instructions[].instruction_text string No The step, HTML. text is accepted instead.
instructions[].title string No Step title.
instructions[].group_name string No Section heading.
instructions[].group_order, instructions[].sort_order integer No Position of the group, then of the step. Default 0.
instructions[].timer_seconds integer No Timer in seconds.
instructions[].duration integer No Timer in minutes, used when timer_seconds is not sent.
instructions[].image_id integer No Attachment id of a step photo.
instructions[].video_url string No Video link.
instructions[].tip string No A tip shown with the step.

Send either timer field and the other is filled in: 240 seconds is stored with a duration of 4; seconds round to the nearest minute, and never below 1. The recipe’s modified_at is updated.

{
  "instructions": [
    "Whisk the flour, milk and lemon zest.",
    {
      "instruction_text": "Cook each pancake for 2 minutes a side.",
      "timer_seconds": 240,
      "sort_order": 1
    }
  ]
}

Responses

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

{
  "success": true,
  "message": "",
  "data": [
    {
      "id": "201",
      "recipe_id": "12",
      "group_name": "",
      "group_order": "0",
      "sort_order": "0",
      "title": "",
      "instruction_text": "Whisk the flour, milk and lemon zest.",
      "image_id": null,
      "video_url": "",
      "duration": null,
      "timer_seconds": null,
      "tip": "",
      "text": "Whisk the flour, milk and lemon zest."
    },
    {
      "id": "202",
      "recipe_id": "12",
      "group_name": "",
      "group_order": "0",
      "sort_order": "1",
      "title": "",
      "instruction_text": "Cook each pancake for 2 minutes a side.",
      "image_id": null,
      "video_url": "",
      "duration": "4",
      "timer_seconds": "240",
      "tip": "",
      "text": "Cook each pancake for 2 minutes a side."
    }
  ]
}
Field Type Meaning
data[].id string The step’s id. Steps get new ids on every replace
data[].instruction_text string The step, HTML
data[].text string A copy of instruction_text
data[].title string Optional step title
data[].group_name string Section heading. Empty when ungrouped
data[].group_order, data[].sort_order string Position of the group, then of the step
data[].timer_seconds string|null Timer length in seconds
data[].duration string|null The same timer in whole minutes
data[].image_id string|null Step photo. image_url and image_thumbnail are added when set
data[].video_url, data[].tip string Optional video link and tip

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/instructions" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"instructions":["Whisk the flour, milk and lemon zest.",{"instruction_text":"Cook each pancake for 2 minutes a side.","timer_seconds":240,"sort_order":1}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-recipe/v1/recipes/12/instructions');
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([
        'instructions' => [
            'Whisk the flour, milk and lemon zest.',
            [
                'instruction_text' => 'Cook each pancake for 2 minutes a side.',
                'timer_seconds'    => 240,
                '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/instructions', {
  method: 'PUT',
  headers: {
    'Authorization': auth,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"instructions": ["Whisk the flour, milk and lemon zest.", {"instruction_text": "Cook each pancake for 2 minutes a side.", "timer_seconds": 240, "sort_order": 1}]}),
});
const { data } = await response.json();

Quick Links

Share