Subscribe to Webhooks
You can subscribe to a webhook using the Nautical API or through the Dashboard. This article will walk you through using the API.
Create a custom appβ
Webhooks are added under apps in your marketplace. Configuring a webhook begins with creating a custom app with the proper permissions.
See Manage Custom Apps for more information.
Create a webhookβ
For example, letβs say you want to measure the drop-off at checkout. You would need to receive notifications from your webhook app when a customer enters the checkout process and when an order is created.
Use the webhookCreate
mutation to add a webhook.
The mutation.webhookCreate
takes the following inputs:
name
: A name to identify the webhook.targetUrl
: The URL to receive the payload.events
: The events that webhook wants to subscribe to. A list of events can be found in theWebhookEventTypeEnum
API reference.app
: Theid
of the app to which the webhook belongs.isActive
: Whether to activate the webhook.secretKey
: (Optional) This key is used to create a hash signature for each webhook payload. Nautical generates an HMAC SHA256 header using the provided secret key and the payload body. The secret key is sent in thex-nautical-signature
HTTP header.
To get the App ID, we can run the apps
query:
query {
apps(first: 100) {
edges {
node {
id
name
}
}
}
}
Now we can run the webhookCreate
mutation:
mutation {
webhookCreate(
input: {
name: "Checkout drop-off"
targetUrl: "https://checkout-drop-off.example.com"
events: [CHECKOUT_CREATED, ORDER_CREATED]
app: "QXBwPkj="
isActive: true
secretKey: "secret-key"
}
) {
webhook {
id
}
webhookErrors {
field
code
}
}
}
Update and delete webhooksβ
To manage the webhooks you will use mutation.webhookDelete
and mutation.webhookUpdate
.
Query webhooksβ
To get the webhook ID needed for these mutations, you can request webhooks information with the apps
query.
For example, the following query returns the first 15
apps and their webhooks:
query {
apps(first: 15) {
edges {
node {
id
name
webhooks {
id
name
events {
eventType
}
isActive
}
}
}
}
}
Update a webhookβ
Update the fields under a webhook using the webhookUpdate
mutation:
mutation {
webhookUpdate(id: "QXBwPkj=", input: { isActive: false }) {
webhook {
isActive
}
webhookErrors {
field
code
}
}
}
Delete a webhookβ
Delete a webhook using the webhookDelete
mutation:
mutation {
webhookDelete(id: "QXBwPkj=") {
webhookErrors {
field
code
}
}
}