{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/postking-app/json-schema/postking-app-tool-create-body-schema.json",
  "title": "ToolCreateBody",
  "description": "Create a Brand Tool page (a form at /tools/{slug} on the brand's domain) with the full tool spec in one call. Publish only after tool_preview shows an empty missingKeys array — call tool_publish when ready.",
  "x-generated": "2026-11-21",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/postking-app-openapi.json#/components/schemas/ToolCreateBody",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "slug": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "endpointUrl": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "The client's own backend URL PostKing POSTs (or GETs, per endpointMethod) form submissions to, as { toolSlug, runId, inputs, visitor } with \"Authorization: Bearer {apiKey}\". Omit or pass null for kind \"none\" — a pure lead-capture tool with no backend call; execute then skips the forward and the result is just the visitor's own inputs echoed back through resultTemplate/handoffUrl."
    },
    "endpointMethod": {
      "type": "string",
      "enum": [
        "GET",
        "POST"
      ],
      "description": "How the visitor's inputs reach endpointUrl. \"POST\" (default): a JSON body. \"GET\": the inputs are appended as a query string instead."
    },
    "apiKey": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Write-only. Sent as the endpoint's Authorization: Bearer token; never echoed back by tool_get/tool_list/tool_create/tool_update — those expose apiKeyLast4 (last 4 characters, or null) instead."
    },
    "isAsync": {
      "type": "boolean"
    },
    "inputSchema": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "number",
              "email",
              "url",
              "select",
              "textarea"
            ]
          },
          "required": {
            "type": "boolean"
          },
          "placeholder": {
            "type": "string"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "key",
          "label",
          "type"
        ]
      }
    },
    "resultType": {
      "type": "string",
      "enum": [
        "json",
        "text",
        "url"
      ]
    },
    "conversionCopy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "ctaHeadline": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "benefitBullets": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "usageLabel": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "showUsageCount": {
      "type": "boolean"
    },
    "sampleOutput": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Free-text sample of what the client endpoint returns — used as the default sampleResponse for tool_preview when the call omits one."
    },
    "usageLimitPerDay": {
      "anyOf": [
        {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        {
          "type": "null"
        }
      ],
      "description": "Caps executions per visitor (guest token or IP) per UTC day. null (default): no limit. Exceeding it returns 429 { code: \"LIMIT_REACHED\", resetsAt }."
    },
    "usageCountStart": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0
        },
        {
          "type": "null"
        }
      ],
      "description": "A seeded starting point added to the real run count for the public usage counter — lets a freshly launched tool open on a number other than zero. null/0 clears it."
    },
    "showTestimonials": {
      "type": "boolean"
    },
    "resultTemplate": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Mustache-style HTML template rendered against the client endpoint's JSON response and the visitor's own submitted inputs. Placeholders: {{path.to.value}} (dotted path into the response JSON) and {{input.<key>}} (a submitted form value, e.g. {{input.email}}). No loops or conditionals ({{#if}}/{{#each}} are left as literal text). A missing value renders as \"\" (never the literal placeholder). Sanitized server-side on write (script tags, inline handlers, and iframes are stripped/rejected) — placeholders survive sanitization intact. When null, the renderer falls back to legacy resultType (json/text/url) rendering."
    },
    "handoffMode": {
      "type": "string",
      "enum": [
        "result",
        "redirect"
      ],
      "description": "\"result\": show the rendered resultTemplate with a Continue button pointing at the filled handoffUrl (hidden when handoffUrl is null). \"redirect\": skip the result screen and redirect immediately once the response (or, for async tools, the poll) resolves."
    },
    "handoffUrl": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Where the visitor is sent after (or instead of) the result. Uses the same {{path.to.value}} / {{input.<key>}} placeholder syntax as resultTemplate — e.g. \"https://client.com/signup?score={{score}}&email={{input.email}}\". The client endpoint's own JSON response may include a top-level \"redirectUrl\" field, which overrides this at render time. Ignored when handoffMode is \"result\" and no missingKeys remain empty at preview time — see tool_preview."
    },
    "failureMessage": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "What the visitor sees when the client endpoint's call fails (non-2xx, timeout, DNS failure) — the upstream error detail is never shown to a visitor. null/empty falls back to a generic failure line."
    },
    "layout": {
      "type": "string",
      "enum": [
        "split",
        "video",
        "product"
      ]
    },
    "layoutConfig": {
      "type": "object",
      "properties": {
        "eyebrow": {
          "type": "string"
        },
        "chips": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "deliverables": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "deliverablesTitle": {
          "type": "string"
        },
        "showDeliverables": {
          "type": "boolean"
        },
        "formHeadline": {
          "type": "string"
        },
        "submitLabel": {
          "type": "string"
        },
        "formSubcopy": {
          "type": "string"
        },
        "formCaption": {
          "type": "string"
        },
        "sampleHeadline": {
          "type": "string"
        },
        "sampleCopy": {
          "type": "string"
        },
        "sampleImageUrl": {
          "type": "string"
        },
        "sampleImageAssetId": {
          "type": "string"
        },
        "sampleImageKind": {
          "type": "string",
          "enum": [
            "image",
            "video"
          ]
        },
        "sampleMetrics": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            },
            "required": [
              "label",
              "value"
            ]
          }
        },
        "videoUrl": {
          "type": "string"
        },
        "videoAssetId": {
          "type": "string"
        },
        "videoPosterUrl": {
          "type": "string"
        },
        "videoPosterAssetId": {
          "type": "string"
        },
        "videoDurationLabel": {
          "type": "string"
        },
        "videoControls": {
          "type": "boolean"
        },
        "steps": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "copy": {
                "type": "string"
              }
            },
            "required": [
              "label",
              "title",
              "copy"
            ]
          }
        },
        "logoUrls": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "description": "Layout-specific page content (eyebrow, chips, sample band, video fields, three-step grid, etc.) — which keys render depends on `layout`. Unknown keys are stripped; a layout only ever shows the keys it supports."
    }
  },
  "required": [
    "name",
    "slug"
  ]
}