Webhooks

Setup webhooks and ensure your server is only receiving the expected Ticket Spot requests for security reasons.

Once your server is configured to receive payloads, it'll listen for any payload sent to the endpoint you configured. For security reasons, you probably want to limit requests to those coming from Ticket Spot. There are a few ways to go about this--for example, you could opt to allow requests from Ticket Spot's IP address--but a far easier method is to set up a secret token and validate the information.

To setup webhooks

  1. Go to "Automations" within your dashboard

  2. Select your trigger type you want to trigger events from

  3. Select "Webhook" from the action list

  4. Enter a destination URL where the payload will be sent

  5. Enter a secret token that you will use to verify the header signature

Validating payloads from Ticket Spot

When your secret token is set, Ticket Spot uses it to create a hash signature with each payload. This hash signature is included with the headers of each request as x-ts-signature-256.

For example, if you have a basic server that listens for webhooks, it might be configured similar to this:

require 'sinatra'
require 'json'

post '/payload' do
  request.body.rewind
  push = JSON.parse(request.body.read)
  "I got some JSON: #{push.inspect}"
end

The intention is to calculate a hash using your SECRET_TOKEN, and ensure that the result matches the hash from Ticket Spot. Ticket Spot uses an HMAC hex digest to compute the hash, so you could reconfigure your server to look a little like this:

post '/payload' do
  payload_body = request.body.read
  verify_signature(payload_body)
  push = JSON.parse(payload_body)
  "I got some JSON: #{push.inspect}"
end

def verify_signature(payload_body)
  signature = 'sha256=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ENV['SECRET_TOKEN'], payload_body)
  return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_TS_SIGNATURE_256'])
end

Last updated