-
Notifications
You must be signed in to change notification settings - Fork 70
Webhooks
Igor Balos edited this page Nov 7, 2019
·
9 revisions
For these API requests you will need to use a server API token. Once you obtain it, you will need to use server API client.
server_token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
client = Postmark::ApiClient.new(server_token)
client.get_webhooks()
# => [{:id=>12345,:url=>"http://example.com",:message_stream=>"outbound",:triggers=>{"Open"=>{"Enabled"=>false, "PostFirstOpenOnly"=>false}, "Click"=>{"Enabled"=>false}, "Delivery"=>{"Enabled"=>false}, "Bounce"=>{"Enabled"=>false, "IncludeContent"=>false}, "SpamComplaint"=>{"Enabled"=>false, "IncludeContent"=>false}}},{:id=>23456,:url=>"http://example.com",:message_stream=>"outbound",:triggers=>{"Open"=>{"Enabled"=>false, "PostFirstOpenOnly"=>false}, "Click"=>{"Enabled"=>false}, #"Delivery"=>{"Enabled"=>false}, "Bounce"=>{"Enabled"=>false, "IncludeContent"=>false}, "SpamComplaint"=>{"Enabled"=>false, "IncludeContent"=>false}}}]
You can get the full webhook information by using it's ID.
# get webhook by ID
client.get_webhook(12345)
# => {:id=>12345,:url=>"http://example.com", :message_stream=>"outbound",:triggers=>{"Open"=>{"Enabled"=>false, "PostFirstOpenOnly"=>false}, "Click"=>{"Enabled"=>false}, "Delivery"=>{"Enabled"=>false}, "Bounce"=>{"Enabled"=>false, "IncludeContent"=>false}, "SpamComplaint"=>{"Enabled"=>false, "IncludeContent"=>false}}}
You can easily create a new webhook with create_webhook
method:
client.create_webhook(
{:url=>"http://example.com",
:message_stream=>"outbound",
triggers: {
Open: { Enabled: true, PostFirstOpenOnly: true },
Click: { Enabled: true },
Delivery: { Enabled: true},
Bounce: { Enabled: true, IncludeContent: false },
SpamComplaint: { Enabled: true, IncludeContent: false }
}
})
# => {:id=>12345,:url=>"http://example.com", :message_stream=>"outbound",:triggers=>{"Open"=>{"Enabled"=>false, "PostFirstOpenOnly"=>false}, "Click"=>{"Enabled"=>false}, "Delivery"=>{"Enabled"=>false}, "Bounce"=>{"Enabled"=>false, "IncludeContent"=>false}, "SpamComplaint"=>{"Enabled"=>false, "IncludeContent"=>false}}}
You can update webhook by identifying it by ID and providing data you wish to update.
client.update_webhook(12345, {:url=>"http://test_updated.com"})
# => {:id=>12345,:url=>"http://example.com", :message_stream=>"outbound",:triggers=>{"Open"=>{"Enabled"=>false, "PostFirstOpenOnly"=>false}, "Click"=>{"Enabled"=>false}, "Delivery"=>{"Enabled"=>false}, "Bounce"=>{"Enabled"=>false, "IncludeContent"=>false}, "SpamComplaint"=>{"Enabled"=>false, "IncludeContent"=>false}}}
client.delete_webhook(12345)
# => {:error_code=>0, :message=>"Webhook 12345 removed."}
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.
- Email sending
- Test email sending
- Bounces
- Templates
- Templates push
- Server
- Servers
- Message Streams
- Webhooks
- Messages
- Domains
- Sender Signatures
- Stats
- Trigger Tags
- Suppressions
- Data Removals
- Trigger Inbound Rules
- Parsing Inbound
- Using Postmark with Mail library
- Accessing Postmark Message ID
- Error Handling
- Integration Testing
- Troubleshooting
- Known issues and how to resolve them