-
Notifications
You must be signed in to change notification settings - Fork 21
Working with webhooks
Postmark Java library allows you to easily retrieve Postmark webhooks and convert these to objects you can use within your java application.
In order to do that, we are going to share a simple example how to retrieve webhooks.
To retrieve a webhook, you can use HttpClient within Postmark Java library.
HttpClient client = new HttpClient(new MultivaluedHashMap<>());
HttpClient.ClientResponse response = client.execute(HttpClient.REQUEST_TYPES.GET, "http://webhooks-example.com");
Once you retrieved the content, all you need is to convert that response to appropriate object. You need to make sure you are trying to convert single webhook object in response to an object, otherwise you will get error.
For conversion, we will use DataHandler class of Postmark Java library.
DataHandler dataHandler = new DataHandler();
Retrieve Bounce webhook:
BounceWebhook bounceWebhook = dataHandler.fromJson(response.getMessage(), BounceWebhook.class);
Retrieve Delivery webhook:
DeliveryWebhook deliveryWebhook = dataHandler.fromJson(response.getMessage(), DeliveryWebhook.class);
Retrieve Open webhook:
OpenWebhook openWebhook = dataHandler.fromJson(response.getMessage(), OpenWebhook.class);
Retrieve Click webhook:
ClickWebhook clickWebhook = dataHandler.fromJson(response.getMessage(), ClickWebhook.class);
Retrieve Inbound webhook:
InboundWebhook inboundWebhook = dataHandler.fromJson(response.getMessage(), InboundWebhook.class);
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.