> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/stackai-api/rest-api-v2/webhook-subscriptions/post-v2-webhooks-subscriptions.md).

# POST /v2/webhooks/subscriptions

## Create Webhook Subscription

> Register a webhook endpoint and return its signing secret.\
> \
> The secret is returned only here. It cannot be recovered later, so a caller that loses it\
> has to delete the subscription and create a new one.\
> \
> \*\*How to use\*\*\
> \
> Configure and test an HTTPS receiver first. Capture the returned signing secret immediately; it is returned only at creation. Use an authorized administrator session for org.webhooks.manage, which is not an assignable restricted API-key scope. Verify event emission in your deployment before relying on callbacks.\
> \
> \*\*Authentication and permissions\*\*\
> \
> Required permissions: \`org.webhooks.manage\`. Resource and owner access checks also apply.\
> \
> \*\*Prepare request.json\*\*\
> \
> Save the example body below as \`request.json\` for the curl sample. Replace example IDs, node keys, and dynamic configuration with values for your organization; these are illustrative, not pre-existing resources.\
> \
> \`\`\`json\
> {\
> &#x20; "url": "<https://your-service.example.com/webhooks/stackai",\\>
> &#x20; "event\_types": \[\
> &#x20;   "run.succeeded",\
> &#x20;   "run.failed"\
> &#x20; ]\
> }\
> \`\`\`

````json
{"openapi":"3.1.0","info":{"title":"StackAI API","version":"0.1.0"},"tags":[{"name":"endpoint-createWebhookSubscriptionV2"}],"servers":[{"url":"https://api.stack-ai.com","description":"Hosted API. Use your deployment-specific origin for private installations."}],"security":[{"HTTPBearer":[]}],"components":{"securitySchemes":{"HTTPBearer":{"type":"http","scheme":"bearer","description":"Personal API key (sk_...) or supported user access JWT. See Authentication and authorization for endpoint restrictions and scopes. Use exactly one Authorization header."}},"schemas":{"CreateWebhookSubscriptionRequestV2":{"properties":{"url":{"type":"string","title":"Url","description":"The HTTPS endpoint that receives the signed event payloads."},"event_types":{"items":{"$ref":"#/components/schemas/WebhookEventType"},"type":"array","title":"Event Types","description":"Event types this subscription receives, for example `run.succeeded`."}},"additionalProperties":false,"type":"object","required":["url","event_types"],"title":"CreateWebhookSubscriptionRequest","description":"A new webhook subscription on the public v2 surface."},"WebhookEventType":{"type":"string","enum":["run.started","run.step.succeeded","run.step.failed","run.succeeded","run.failed","run.cancelled"],"title":"WebhookEventType","description":"Event types a subscription may register for; producers emit these (runs producer lands separately)."},"StackAIAPIDataResponse_WebhookSubscriptionWithSecretResponseV2_":{"properties":{"response_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Response Code","description":"Machine-readable response code, when provided."},"meta":{"additionalProperties":true,"type":"object","title":"Meta","description":"Additional metadata","default":{}},"data":{"$ref":"#/components/schemas/WebhookSubscriptionWithSecretResponseV2","description":"Data returned by the API service"}},"type":"object","required":["data"],"title":"StackAIAPIDataResponse[WebhookSubscriptionWithSecretResponseV2]"},"WebhookSubscriptionWithSecretResponseV2":{"properties":{"subscription_id":{"type":"string","title":"Subscription Id"},"url":{"type":"string","title":"Url"},"event_types":{"items":{"$ref":"#/components/schemas/WebhookEventType"},"type":"array","title":"Event Types"},"created_at":{"type":"string","format":"date-time","title":"Created At"},"secret":{"type":"string","title":"Secret","description":"The signing secret for verifying deliveries. Shown only in this response and never retrievable afterwards; store it now, or delete the subscription and create a new one to get another secret."}},"type":"object","required":["subscription_id","url","event_types","created_at","secret"],"title":"WebhookSubscriptionWithSecretResponse","description":"A freshly created subscription, carrying its one-time signing secret."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v2/webhooks/subscriptions":{"post":{"tags":["endpoint-createWebhookSubscriptionV2"],"summary":"Create Webhook Subscription","description":"Register a webhook endpoint and return its signing secret.\n\nThe secret is returned only here. It cannot be recovered later, so a caller that loses it\nhas to delete the subscription and create a new one.\n\n**How to use**\n\nConfigure and test an HTTPS receiver first. Capture the returned signing secret immediately; it is returned only at creation. Use an authorized administrator session for org.webhooks.manage, which is not an assignable restricted API-key scope. Verify event emission in your deployment before relying on callbacks.\n\n**Authentication and permissions**\n\nRequired permissions: `org.webhooks.manage`. Resource and owner access checks also apply.\n\n**Prepare request.json**\n\nSave the example body below as `request.json` for the curl sample. Replace example IDs, node keys, and dynamic configuration with values for your organization; these are illustrative, not pre-existing resources.\n\n```json\n{\n  \"url\": \"https://your-service.example.com/webhooks/stackai\",\n  \"event_types\": [\n    \"run.succeeded\",\n    \"run.failed\"\n  ]\n}\n```","operationId":"createWebhookSubscriptionV2","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWebhookSubscriptionRequestV2"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StackAIAPIDataResponse_WebhookSubscriptionWithSecretResponseV2_"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
````


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/stackai-api/rest-api-v2/webhook-subscriptions/post-v2-webhooks-subscriptions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
