json.actions

Mutate only the top-level actions array.

Input
Serialized JSON array from the response actions field, or [] when absent.
Route matching
Same prefix rules as json.response.
Pipeline
Runs after json.response. Output is inserted into the top-level actions field.

Use this for panel steps, links, and plugin-specific operator actions.

Use cases

  • Add plugin documentation links
  • Expose plugin-specific actions to CloudPanel

Example

Registration and handler

Register

hook_json!(host, JsonMutateTarget::ResponseActions, "/api/system", on_actions);

Handler

extern "C" fn on_actions(ctx: *const JsonMutateContext) -> i32 {
    let ctx = unsafe { &*ctx };
    let input = unsafe { std::slice::from_raw_parts(ctx.json_in_ptr, ctx.json_in_len) };
    let Ok(mut actions) = serde_json::from_slice::<Vec<serde_json::Value>>(input) else {
        return JSON_MUTATE_UNCHANGED;
    };
    actions.push(serde_json::json!({
        "id": "plugin_action",
        "label": "Plugin action",
        "step": "GET /plugins/example"
    }));
    let Ok(out) = serde_json::to_vec(&actions) else {
        return JSON_MUTATE_UNCHANGED;
    };
    write_json_output(ctx, &out)
}

← All JSON hooks