Templates

By default webhooks push data to your server in a JSON format, however this can be changed by using templates. Templates allow you to specify the text format for the data sent to your endpoint. They can be used to format the message into a different JSON structure, into readable text, or even into another format like XML.

The following shows an example template created on the platform which formats the webhook data in a custom JSON format:

{
   "latitude": {Location.Latitude},
   "longitude": {Location.Longitude},
   "temperature": {Temperature.Celsius},
   "utcTime": {EntryTime.Utc},
   "shipment": {ShipmentId},
   "myCustomData": "Here is my custom non-Tive data"
}

A full list of variables available to use within templates can be found here.

Specifying Templates via the Platform

Templates can be provided in the platform on the "Create New Webhook" and "Update Webhook" screens in the "Template" field.

Specifying Templates via the API

To create the same custom template via API, the template field in the Create a Webhook or Update a Webhook endpoints would look like this within a request:

{
     "template": "{\"latitude\": {Location.Latitude},\"longitude\": {Location.Longitude},\"temperature\": {Temperature.Celsius},\"utcTime\": {EntryTime.Utc},\"shipment\": {ShipmentId},\"myCustomData\": \"Here is my custom non-Tive data\"}",
     "name": "Custom Template Via API",
     "url": "https://www.example.com/webhooksGoHere",
     "enabled": true,
     "applyToAllTrackers": true
}

A Few Notes on Template Variables

  • Template Variables are defined using curly braces: {MyVariable}.
  • The Tive system will replace template variables with their value or “N/A” if the variable name is unknown or has no value.
  • Valid variable names utilize letters and the ‘.’ (dot) character.
  • The complete list of variable names available can be found here.
  • The output of each variable can be formatted using formatters which can be specified by adding a colon after the variable name within the curly braces. More information about formatters can be found here.