Skip to main content

Create your first webhook in Momento

To complete step one of setting up the webhook, log into the Momento console. Navigate to the cache list on the left navigation bar and select the cache that will publish to the webhook.

To create the webhook, a few simple details need to be supplied.

Webhook Creation

The three fields presented are important for different reasons.

  • Webhook Name: Human-readable name for the webhook.
  • Topic Name: Topic that will trigger the webhook when published.
  • Webhook Destination: Endpoint URL of the webhook to POST to.

Next, create a Fine-Grained Access Key for the cache, with topic publish permissions.

Token Creation

Using this token, you can now start publishing to the topic. You can use the Momento SDK to publish to the topic.

const result = await topicClient.publish(cacheName, 'test-topic', 'test-topic-value');
switch (result.type) {
case TopicPublishResponse.Success:
console.log("Value published to topic 'test-topic'");
break;
case TopicPublishResponse.Error:
throw new Error(
`An error occurred while attempting to publish to the topic 'test-topic' in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
info
Full example code and imports can be found here

You should now be able to see the events being received by your webhook endpoint. What this endpoint does with the events is up to you! It is worth noting that this Webhook can listen to multiple topics across multiple caches. Since the topic and cache come as part of the POST body, events can be distinguished by these attributes, and processed in differently depending on which Cache/Topic the event came from.