|
| 1 | +--- |
| 2 | +title: "Webhooks API" |
| 3 | +url: /apidocs-mxsdk/apidocs/webhooks-api/ |
| 4 | +type: swagger |
| 5 | +category: "API Documentation" |
| 6 | +weight: 97 |
| 7 | +tags: ["API", "webhooks", "Mendix Cloud"] |
| 8 | +--- |
| 9 | + |
| 10 | +{{% alert color="warning" %}} This feature is in Beta. For more information on Beta products, see [Beta Releases](/releasenotes/beta-features/). {{% /alert %}} |
| 11 | + |
| 12 | +## 1 Introduction |
| 13 | + |
| 14 | +The Mendix Webhooks API allows you to manage [webhooks](/developerportal/deploy/webhooks/). |
| 15 | + |
| 16 | +You can use the API to do the following: |
| 17 | + |
| 18 | +* List all webhooks |
| 19 | +* Get a webhook |
| 20 | +* Create a webhook |
| 21 | +* Update a webhook |
| 22 | +* Delete a webhook |
| 23 | + |
| 24 | +## 2 Authentication{#authentication} |
| 25 | + |
| 26 | +Authentication for the Webhooks API uses a personal access token (PAT). |
| 27 | + |
| 28 | +### 2.1 Generating a PAT |
| 29 | + |
| 30 | +To generate a PAT, see the [Personal Access Tokens](/developerportal/community-tools/mendix-profile/#pat) section in *Mendix Profile*. |
| 31 | + |
| 32 | +Select the following as scopes: |
| 33 | + |
| 34 | +* `mx:webhook:read` – to perform `GET` operations |
| 35 | +* `mx:webhook:write` – to perform all operations (`GET`, `POST`, `PUT`, and `DELETE`) |
| 36 | + |
| 37 | +Store the generated value `{GENERATED_PAT}` somewhere safe so you can use it to authorize your Mendix Cloud Webhooks API calls. |
| 38 | + |
| 39 | +### 2.2 Using the PAT |
| 40 | + |
| 41 | +Each request must contain an `Authorization` header with the value `MxToken {GENERATED_PAT}`. For example: |
| 42 | + |
| 43 | +```http {linenos=false} |
| 44 | +GET /apps/80a28d6e-c5fc-43d9-87c2-d7d56b07542/webhooks HTTP/1.1 |
| 45 | +Authorization: MxToken 7LJE…vk |
| 46 | +``` |
| 47 | + |
| 48 | +To authenticate calls when using the Open API specification below, click **Authorize** and use the value `MxToken {GENERATED_PAT}`. |
| 49 | + |
| 50 | +## 3 Examples |
| 51 | + |
| 52 | +### 3.1 Using the API to Create and Update a Webhook Endpoint |
| 53 | + |
| 54 | +The following procedure will create a webhook endpoint and update the webhook endpoint: |
| 55 | + |
| 56 | +1. Set up your authentication PAT. |
| 57 | + |
| 58 | +2. To create a wehhook for an app, call `POST /apps/{app-id}/webhooks`. For example: |
| 59 | + |
| 60 | + ```http {linenos=false} |
| 61 | + POST /apps/80a28d6e-c5fc-43d9-87c2-d7d56b07542e/webhooks |
| 62 | + ``` |
| 63 | + |
| 64 | + The API call returns `id`, `name`, `url`, `eventTypes`, `isActive`, `validationSecret` and `headers` of the new webhook, together with status code `200`. |
| 65 | + |
| 66 | +3. To update the new webhook, call `PUT /apps/{app-id}/webhooks/{webhook-id}`, with a request body. For example: |
| 67 | + |
| 68 | + * API call: |
| 69 | + |
| 70 | + ```http {linenos=false} |
| 71 | + PUT /apps/80a28d6e-c5fc-43d9-87c2-d7d56b07542e/webhooks/msg_2M605iBQRge9hTgpYg7fKXQubaw |
| 72 | + ``` |
| 73 | + * Request body: |
| 74 | +
|
| 75 | + ```json |
| 76 | + { |
| 77 | + "name": "string", |
| 78 | + "url": "https://some.domain.com/webhooks", |
| 79 | + "eventTypes": [ |
| 80 | + "teamserver.push" |
| 81 | + ], |
| 82 | + "isActive": true, |
| 83 | + "validationSecret": "PMJhiGo1nTL6wlNyZVFh5v9rLZdcLsG2O", |
| 84 | + "headers": [ |
| 85 | + { |
| 86 | + "key": "Authorization", |
| 87 | + "value": "Beaerer DG4R4GT6R43" |
| 88 | + } |
| 89 | + ] |
| 90 | + } |
| 91 | + ``` |
| 92 | +
|
| 93 | + If the update succeeds, you should receive status code `202`. You can get the updated webhook details by calling `GET apps/{app-id}/webhooks/{webhook-id}`. |
| 94 | +
|
| 95 | +
|
| 96 | +## 4 API Reference |
| 97 | +
|
| 98 | +{{< swaggerui src="/openapi-spec/webhooks.yaml" >}} |
0 commit comments