Files
api-docs/private-plugins/webhooks.md
T

93 lines
3.8 KiB
Markdown
Raw Normal View History

2025-05-06 02:09:28 +00:00
---
2025-07-27 21:40:17 +00:00
description: Send a payload of merge variables to create a custom screen.
2025-05-06 02:09:28 +00:00
---
2025-07-27 21:40:17 +00:00
# Webhooks
2025-05-06 02:09:28 +00:00
{% hint style="info" %}
2025-07-27 21:40:17 +00:00
#### Before you begin
2025-05-06 02:09:28 +00:00
2025-07-27 21:40:17 +00:00
Learn how to build Private Plugins [here](https://help.usetrmnl.com/en/articles/9510536-private-plugins). The guide below only explains how to use the "Webhook" data retrieval strategy.
2025-05-06 02:09:28 +00:00
{% endhint %}
2025-07-27 21:40:17 +00:00
### Rate Limits
_Request volume_
You may send data to TRMNL's server up to 12x per hour. [TRMNL+](https://help.usetrmnl.com/en/articles/11861887-trmnl-faq) subscribers may send up to 30x payloads per hour. Webhooks sent at a faster pace will receive a `429` rate limit response.
_Request size_
You may send up to 2kb of data. [TRMNL+](https://help.usetrmnl.com/en/articles/11861887-trmnl-faq) subscribers may send up to 5kb of data. To stay within these boundaries while also creating a data rich experience, consider using the `deep_merge` and `stream` strategies documented below.
2025-05-06 02:09:28 +00:00
2025-05-09 15:47:15 +00:00
### Authorization
TRMNL has Device API Keys, User API Keys, and Plugin Setting UUIDs. For private plugin screen generation, we'll use your Plugin Settings UUID.
2025-07-27 21:40:17 +00:00
This is accessible from your plugin instance's configuration form > Webhook URL field.
2025-05-09 15:47:15 +00:00
<figure><img src="../.gitbook/assets/TRMNL Private Plugin Webhook URL w UUID.png" alt=""><figcaption><p>Private Plugin Webhook URL w/ UUID</p></figcaption></figure>
{% hint style="info" %}
2025-07-27 21:40:17 +00:00
**Note:** you must "save" (create) a private plugin instance to generate a UUID and Webhook URL.
2025-05-09 15:47:15 +00:00
{% endhint %}
### Set new content
Send a `POST` request to your Webhook URL. Put data inside a `merge_variables` node like so:
2025-05-06 02:09:28 +00:00
```
curl "https://usetrmnl.com/api/custom_plugins/asdfqwerty1234" \
-H "Content-Type: application/json" \
-d '{"merge_variables": {"text":"You can do it!", "author": "Rob Schneider"}}' \
-X POST
```
2025-05-09 15:47:15 +00:00
You will see this payload inside the Your Variables dropdown of the Markup Editor.
2025-05-06 02:09:28 +00:00
2025-05-09 15:47:15 +00:00
<figure><img src="../.gitbook/assets/TRMNL - Your Variables dropdown.png" alt=""><figcaption><p>Your variables - available inside the Markup Editor</p></figcaption></figure>
2025-05-06 02:09:28 +00:00
2025-05-11 00:41:28 +00:00
### Get merge variable content
To fetch existing `merge_variables` from a private plugin, `GET` from the same endpoint:
```
curl "https://usetrmnl.com/api/custom_plugins/asdfqwerty1234"
```
2025-05-09 15:47:15 +00:00
### Update existing content
2025-05-28 18:35:19 +00:00
If your private plugin needs to maintain state over time, for example an ever-growing todo list or a data visualization, you may prefer to send only "new" data points to your TRMNL plugin.
2025-05-09 15:47:15 +00:00
2025-05-28 18:35:19 +00:00
There are two strategies to accomplish this: `deep_merge`, and `stream`.
#### Deep merge strategy
The `deep_merge` strategy combines existing key/value pairs with the new values incoming on the webhook. It's a good way to update nested data with only a few values here and there.
2025-05-09 15:47:15 +00:00
```
curl "https://usetrmnl.com/api/custom_plugins/asdfqwerty1234" \
-H "Content-Type: application/json" \
2025-05-28 18:35:19 +00:00
-d '{"merge_variables": {"sensor": {"temperature": 42}}, "merge_strategy": "deep_merge"}' \
2025-05-09 15:47:15 +00:00
-X POST
```
2025-05-28 18:35:19 +00:00
#### Stream strategy
2025-05-09 15:47:15 +00:00
2025-05-28 18:35:19 +00:00
The `stream` strategy is useful for accumulating values in arrays. Any top-level arrays are appended with the incoming values, and the `stream_limit` parameter ensures that old values drop off the arrays so they don't grow forever.
```
curl "https://usetrmnl.com/api/custom_plugins/asdfqwerty1234" \
-H "Content-Type: application/json" \
-d '{"merge_variables": {"temperatures": [40, 42]}, "merge_strategy": "stream", "stream_limit": 10}' \
-X POST
```
Now you may iterate through the combined data inside your markup, for example:
2025-07-27 21:40:17 +00:00
<figure><img src="../.gitbook/assets/CleanShot 2025-05-28 at 14.33.07@2x.png" alt=""><figcaption><p>Accessing streamed webhook data</p></figcaption></figure>
2025-05-06 02:09:28 +00:00
## Troubleshooting
2025-05-09 15:47:15 +00:00
For more help, see our [Private Plugin guide](https://help.usetrmnl.com/en/articles/9510536-custom-plugins) or join the developer Discord from your account tab.