Create webhook
Changed onCreates a new webhook with settings provided by the webhook object passed as JSON in the payload. The response is the created webhook object.
To avoid duplicating a webhook, use the idempotencyKey parameter in the request body. Multiple calls to create a webhook with the same idempotencyKey will only create the webhook with the first call and return the existing webhook on subsequent calls. Idempotency keys must be unique, so use a UUID or another random string with enough entropy.
To assign the new webhook to an Actor or task, the request body must contain requestUrl, eventTypes, and condition properties.
- requestUrl is the webhook's target URL, to which data is sent as a POST request with a JSON payload.
- eventTypes is a list of events that will trigger the webhook, e.g. when the Actor run succeeds.
- condition should be an object containing the ID of the Actor or task to which the webhook will be assigned.
- payloadTemplate is a JSON-like string, whose syntax is extended with the use of variables.
- headersTemplate is a JSON-like string, whose syntax is extended with the use of variables. Following values will be re-written to defaults: "host", "Content-Type", "X-Apify-Webhook", "X-Apify-Webhook-Dispatch-Id", "X-Apify-Request-Origin"
- description is an optional string.
- shouldInterpolateStrings is a boolean indicating whether to interpolate variables contained inside strings in the payloadTemplate
"isAdHoc" : false,
"requestUrl" : "https://example.com",
"eventTypes" : [
"ACTOR.RUN.SUCCEEDED",
"ACTOR.RUN.ABORTED"
],
"condition" : {
"actorId": "5sTMwDQywwsLzKRRh",
"actorTaskId" : "W9bs9JE9v7wprjAnJ"
},
"payloadTemplate": "",
"headersTemplate": "",
"description": "my awesome webhook",
"shouldInterpolateStrings": false,
Important: The request must specify the Content-Type: application/json HTTP header.
Request
- Base URLhttps://api.apify.com
- Auth
- HTTP bearer
- or API key in query parameter token
Request body
Example request
{
"eventTypes": [
"ACTOR.RUN.SUCCEEDED"
],
"condition": {
"actorId": "hksJZtadYvn4mBuin",
"actorTaskId": "asdLZtadYvn4mBZmm",
"actorRunId": "hgdKZtadYvn4mBpoi"
},
"idempotencyKey": "fdSJmdP3nfs7sfk3y",
"requestUrl": "http://example.com/",
"payloadTemplate": "{\\n \"userId\": {{userId}}...",
"headersTemplate": "{\\n \"Authorization\": \"Bearer ...\"}",
"description": "this is webhook description"
}Response
Example response
{
"data": {
"id": "YiKoxjkaS9gjGTqhF",
"createdAt": "2019-12-12T07:34:14.202Z",
"modifiedAt": "2019-12-13T08:36:13.202Z",
"userId": "wRsJZtadYvn4mBZmm",
"isEnabled": true,
"actionType": "HTTP_REQUEST",
"eventTypes": [
"ACTOR.RUN.SUCCEEDED"
],
"condition": {
"actorId": "hksJZtadYvn4mBuin",
"actorTaskId": "asdLZtadYvn4mBZmm",
"actorRunId": "hgdKZtadYvn4mBpoi"
},
"requestUrl": "http://example.com/",
"payloadTemplate": "{\\n \"userId\": {{userId}}...",
"headersTemplate": "{\\n \"Authorization\": \"Bearer ...\"}",
"title": "Notify on failure",
"description": "this is webhook description",
"slackMessage": {
"userIntegrationId": "kLcd8Z4dzXN1z3QzS",
"channelId": "C01234ABCDE",
"messageTemplate": "Actor run {{resource.id}} finished."
},
"googleMail": {
"userIntegrationId": "kLcd8Z4dzXN1z3QzS",
"emailTo": [
"bob@example.com"
],
"subject": "Actor run finished",
"body": "Actor run {{resource.id}} finished.",
"attachmentFormat": "csv",
"attachmentTransformation": {
"fields": [
"title",
"url"
],
"omit": [
"html"
]
}
},
"googleDrive": {
"userIntegrationId": "kLcd8Z4dzXN1z3QzS",
"filename": "results",
"format": "json",
"transformation": {
"fields": [
"title",
"url"
],
"omit": [
"html"
]
}
},
"githubIssue": {
"userIntegrationId": "kLcd8Z4dzXN1z3QzS",
"repository": "apify/apify-docs",
"title": "Actor run failed",
"body": "Actor run {{resource.id}} failed."
},
"lastDispatch": {
"finishedAt": "2019-12-13T08:36:13.202Z"
},
"stats": {
"totalDispatches": 1
}
}
}Changes
- info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status
- info
- info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status - info
added the optional property
/to the response with the status
- info