Webhook API
Overview
The djctl Webhook API provides a simple mechanism for providing real-time track transition updates to an HTTP or HTTPS endpoint.
Connection details
When launching djctl, use the --webhook.url
command line parameter to configure an HTTP or HTTPS endpoint.
Event data
As a new track transitions into “featured” state, a JSON formatted message is sent as an HTTP POST to the defined webhook.url
. The following is an example message:
Attribute dictionary
The following table enumerates default attributes found in the event JSON. Each of these attribute names can be customized in the JSON payload using the specified flag.
Attribute | Flag | Type | Description |
---|---|---|---|
title | --webhook.json.title | string | Track title |
artist | --webhook.json.artist | string | Track artist |
genre | --webhook.json.genre | string | Track genre |
art | --webhook.json.art | string | Track album art as Base64 encoded PNG (RGB, 256x256) |
spotify_code | --webhook.json.spotify | string | Spotify code image as Base64 encoded PNG |
duration | --webhook.json.duration | integer | Total track duration in seconds |
timestamp | --webhook.json.timestamp | string | Timestamp in format 2022-02-11T08:24:47.162918-08:00 |
timestamp_epoch | --webhook.json.epoch | integer | Unix time; the number of seconds elapsed since January 1, 1970 UTC |
elapsed | --webhook.json.elapsed | string | Elapsed time since the first track triggered in format hh:mm:ss |
Custom JSON messages
Using the attribute flags in the previous table, the Webhook JSON message can be customized. For example, to move all attributes under a top-level data
key, the following flags can be supplied:
The following is equivalent configuration YAML.
The following is the resulting JSON message. Notice fields are now nested under the data
key.
Using Webhook JSON configuration flags, fields can also be omitted. The following flags remove album art and the Spotify code.
The following is equivalent configuration YAML.
The following is the resulting JSON message. Notice the art
and spotify_code
keys are not present.
Custom format string
An optional string field is available for inclusion in the JSON message using a combination of the --webhook.format
and --webhook.json.format
flags. The --webhook.format
flag specifies a substitution variable string and the --webhook.json.format
flag specifies the key path for this string in the Webhook JSON message.
The example flags below insert a custom field named summary
and removes the default art
and spotify_code
fields from the JSON message. The contents of the summary
field are derived using the --webhook.format
string.
The following is an equivalent YAML configuration.
The following is the resulting JSON message.