Svix Webhooks

Svix Webhooks

Webhooks as a Service
                  {
  "eventId": "unique-msg-identifier",
  "eventType": "user.signup",
  "payload": {
    "email": "[email protected]",
    "type": "user.created",
    "username": "test_user"
  },
  "channels": [
    "project_123",
    "group_2"
  ],
  "id": "msg_1srOrx2ZWZBpBUvZwXKQmoEYga2",
  "timestamp": "2019-08-24T14:15:22Z"
}
              

Response example. If you want to see more check the documentation.

## Getting started Get your authentication token (`AuthToken`) from the [Svix dashboard](https://dashboard.svix.com). ## Sending messages ### Creating a consumer application Each of your users needs an associated consumer application. The easiest way is to create a new application whenever a user signs up. In this section we will use the [create application API endpoint](https://api.svix.com/docs#operation/create_application_api_v1_app__post) to create an application. You would need the application's ID when sending messages. You can either save the ID returned when creating the application, or set your own unique id (e.g. your user's username or internal database id) in the optional `uid` field and use that instead. ### Send a message We will now send a new message using the [create message API endpoint](https://api.svix.com/docs#operation/create_message_api_v1_app__app_id__msg__post). It accepts an `app_id`, which is the application's ID (or custom `uid`) from the previous section. In addition, it accepts the following fields (as part the json body): - [`eventType`](event-types.mdx): an identifier denoting the type of the event. E.g. `invoice.paid`. - `eventId`: an optional unique ID for the event. This is useful if you want to map each message to unique events on your system. - `payload`: a JSON dictionary that can hold anything. Its content will be sent as the webhook content. #### Including the event type in the payload Webhook consumers often consume multiple event types using the same endpoint. To enable them to be able to differentiate different events, it's common practice to include the event type in the webhook's payload. Svix, however, doesn't automatically inject the event type into the payload, in order to give our customers full control over the content and structure of the payloads they send. Most commonly people include the event type in the payload as a top-level key called `type`, `event_type`, or `eventType`, but it's up to you how you want to call it. ## Add webhook endpoints In the example above we showed how to send messages, though these messages were not sent to any specific URLs. In order for them to be sent, we need to add endpoints. This is what this section is about. :::tip You can use the [Svix Play webhook debugger](https://www.svix.com/play/) and the [Svix CLI](https://github.com/svix/svix-cli) to inspect, test and debug your webhooks during development. ::: ## Closing words That's it! There are only three API calls you should really care about. Creating applications (i.e users), sending messages, and giving your users access to the App Portal. All of them are covered here.