Skip to content

Handling Web Hooks

Igor Balos edited this page Jul 31, 2023 · 6 revisions

Using types on JSON web hooks

If you have setup one or more web hook URLs you will probably retrieve the web hooks with http client of your preference. If you use Typescript, you can use types from Postmark NodeJS library on web hooks you retrieve to manage JSON web hooks easier.

You can find examples below how to do that. In example we are using axios as http client.

const httpClient = require('axios');

httpClient.get("https://www.example.com/inbound-hook").then((response:any) => {
  let inboundWebhook:postmark.Models.InboundWebhook = response.data;
  console.log(inboundWebhook.From)
}).catch((error:Error) => {
  console.log("Error: ", error.message);
});
const httpClient = require('axios');

httpClient.get("https://www.example.com/delivery-hook").then((response:any) => {
  let deliveryWebhook:postmark.Models.DeliveryWebhook = response.data;
  console.log(deliveryWebhook.MessageId);
}).catch((error:Error) => {
  console.log("Error: ", error.message);
});
const httpClient = require('axios');

httpClient.get("https://www.example.com/bounce-hook").then((response:any) => {
  let bounceWebhook:postmark.Models.BounceWebhook = response.data;
  console.log(bounceWebhook.MessageID)
  console.log(bounceWebhook.ServerID)
}).catch((error:Error) => {
  console.log("Error: ", error.message);
});

Webhook types are available in Postmark library since version 3.0.19.