---
title: "preview_snippet — AI Ability"
description: "Preview (test-run) a Code Glue snippet — Test-run a snippet (by snippet_id, or raw code) against a real captured payload WITHOUT dispatching anything."
url: "https://wpwebhooks.org/docs/ability-preview-snippet/"
---

[WP Webhooks](https://wpwebhooks.org/) / [Docs](https://wpwebhooks.org/docs/) / preview\_snippet

AI Ability since v1.3.0

# preview\_snippet

Preview (test-run) a Code Glue snippet — Test-run a snippet (by snippet\_id, or raw code) against a real captured payload WITHOUT dispatching anything.

Test-run a snippet (by snippet\_id, or raw code) against a real captured payload WITHOUT dispatching anything. Pass webhook\_id+trigger to use that webhook's captured example with its stored field mapping applied — the exact array the snippet gets at dispatch — or provide an explicit payload. Returns input\_payload (what the snippet received), the resulting payload, any PHP error and printed output; if the result is identical to input\_payload, the code matched nothing. Always preview before assigning. Registered as the WordPress Ability `flowsystems-webhook-actions/preview-snippet`, so external AI tools (Claude Code, Cursor) can call it over MCP, or over the Abilities REST route with a scoped API token.

/ Plan step shape

```
{ "ability": "preview_snippet", "input": { "snippet_id": …, "code": …, "webhook_id": …, "trigger": …, "payload": …, "mode": … } }
```

/ Scope & confirmation

Minimum API-token scope for external (MCP/REST) callers: `full`. Runs without a confirmation pause (the overall plan is still user-approved before execution starts).

/ Input fields

| Name | In | Type | Req | Description |
| --- | --- | --- | --- | --- |
| snippet\_id | param | integer | — | Saved snippet to run; omit when passing code. |
| code | param | string | — | Raw PHP to run instead of a saved snippet. |
| webhook\_id | param | integer | — | With trigger: use this webhook's captured example payload. |
| trigger | param | string | — |  |
| payload | param | object | — | Explicit test payload; overrides the captured example. |
| mode | param | string | — | Default pre. pre | post |

/ Examples

Plan step as Build with AI proposes it

```
{
  "id": "step_1",
  "ability": "preview_snippet",
  "summary": "…",
  "input": {
    "snippet_id": 4,
    "webhook_id": 12,
    "trigger": "woocommerce_order_status_completed"
  }
}
```

/ Related

[create\_snippet](https://wpwebhooks.org/docs/ability-create-snippet/)[assign\_snippet](https://wpwebhooks.org/docs/ability-assign-snippet/)[REST API reference](https://wpwebhooks.org/webhook-wordpress-plugin-api/)

/Ready

## Your next automation is  
one sentence away.

[Try the Live Preview](https://playground.wordpress.net/?blueprint-url=https://wpwebhooks.org/blueprint.json) [See the Plugin →](https://wpwebhooks.org/wordpress-webhook-plugin/)

$ wp plugin install flowsystems-webhook-actions --activate

## Structured data

```json
{"@context":"https://schema.org","@type":"TechArticle","name":"preview_snippet — AI Ability — Webhook Actions Docs","description":"Preview (test-run) a Code Glue snippet — Test-run a snippet (by snippet_id, or raw code) against a real captured payload WITHOUT dispatching anything.","url":"https://wpwebhooks.org/docs/ability-preview-snippet/","isPartOf":{"@type":"WebSite","name":"WP Webhooks","url":"https://wpwebhooks.org"},"about":{"@type":"SoftwareApplication","name":"Webhook Actions","applicationCategory":"WordPress Plugin"}}
```
