{"article":{"id":360006943354,"url":"https://flockhelp.zendesk.com/api/v2/help_center/en-us/articles/360006943354.json","html_url":"https://support.flock.com/hc/en-us/articles/360006943354-Incoming-webhooks","author_id":115713378234,"comments_disabled":true,"draft":false,"promoted":false,"position":0,"vote_sum":5,"vote_count":5,"upvote_count":5,"downvote_count":0,"section_id":360002095533,"created_at":"2018-07-13T15:22:59Z","updated_at":"2024-08-23T14:34:52Z","name":"Incoming webhooks","title":"Incoming webhooks","source_locale":"en-us","locale":"en-us","outdated":false,"outdated_locales":[],"edited_at":"2021-11-12T06:58:55Z","user_segment_id":null,"user_segment_ids":[],"permission_group_id":499774,"content_tag_ids":[],"label_names":["webhook","incoming webhook","create webhook","connect webhook","transform json"],"body":"<p>You can use Flock's webhooks to send and receive messages from external services using JSON packets. An incoming webhook posts messages to a Flock channel from an external service.</p>\n<h2>Create an incoming webhook</h2>\n<ul>\n<li>Navigate to the <em>Flock Developer Dashboard</em> at <a href=\"https://dev.flock.com/\" target=\"_blank\" rel=\"noopener\">https://dev.flock.com</a>.</li>\n<li>Sign in with your Flock account and click <em>Webhooks</em> on the left.</li>\n</ul>\n<table class=\" wysiwyg-text-align-center\">\n<tbody>\n<tr>\n<td>image-shadow</td>\n<td><img src=\"https://support.flock.com/hc/article_attachments/360025396153/Webhooks_Dev01.png\" alt=\"Webhooks_Dev01.png\"></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Choose to <em>Add</em> an <em>Incoming Webhook</em>.</li>\n<li>Select the <em>Channel</em> where you want incoming messages to be posted.</li>\n</ul>\n<table class=\" wysiwyg-text-align-center\">\n<tbody>\n<tr>\n<td>image-shadow</td>\n<td><img src=\"https://support.flock.com/hc/article_attachments/360024468794/Webhooks_Dev02.png\" alt=\"Webhooks_Dev02.png\"></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Give the webhook a name and an icon that will be used to post messages in Flock.</li>\n</ul>\n<table class=\" wysiwyg-text-align-center\">\n<tbody>\n<tr>\n<td>image-shadow</td>\n<td><img src=\"https://support.flock.com/hc/article_attachments/360025396573/Webhooks_Dev03.png\" alt=\"Webhooks_Dev03.png\"></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Click <em>Save and Generate URL</em>. Copy the URL that is generated.</li>\n<li>This is the webhook endpoint and it accepts JSON packets posted to it. The following command will post a message \"This is a test message\" to your configured channel:</li>\n</ul>\n<table>\n<tbody>\n<tr>\n<td>code-block</td>\n<td>bash</td>\n</tr>\n<tr>\n<td>\n<p><span class=\"wysiwyg-font-size-small\"><code class=\"bash plain\">curl -X POST &lt;Incoming Webhook URL&gt; -H <span style=\"color: blue;\">\"Content-Type: application/json\"</span> -d '{</code></span></p>\n<p><span class=\"wysiwyg-font-size-small\"><code class=\"bash plain\"><span style=\"color: blue;\">\"text\": \"This is a test message\"</span></code></span></p>\n<p><span class=\"wysiwyg-font-size-small\"><code class=\"bash plain\">}'</code></span></p>\n</td>\n<td> </td>\n</tr>\n</tbody>\n</table>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\"></code></span></p>\n<h2>Transforming JSON payload formats</h2>\n<p>Flock's incoming webhooks support Message objects with two common attributes or keys - \"text\" for message content and \"flockml\" for message formatting.</p>\n<table>\n<tbody>\n<tr>\n<td>code-block</td>\n<td>bash</td>\n</tr>\n<tr>\n<td>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">curl -X POST &lt;Incoming Webhook URL&gt; -H <span style=\"color: blue;\">\"Content-Type: application/json\"</span> -d '{</code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\"><span style=\"color: blue;\">\"text\": \"This is a test message.\"</span></code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">}'</code></span></p>\n</td>\n<td> </td>\n</tr>\n</tbody>\n</table>\n<p>OR</p>\n<table>\n<tbody>\n<tr>\n<td>code-block</td>\n<td>bash</td>\n</tr>\n<tr>\n<td>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">curl -X POST &lt;Incoming Webhook URL&gt; -H <span style=\"color: blue;\">\"Content-Type: application/json\"</span> -d '{</code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\"><span style=\"color: blue;\">\"flockml\":\"&lt;flockml&gt;Hello! Welcome to &lt;b&gt;Flock&lt;/b&gt;!&lt;/flockml&gt;\"</span></code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">}'</code></span></p>\n</td>\n<td> </td>\n</tr>\n</tbody>\n</table>\n<p>Some external apps and services may send data that does not follow Flock's JSON payload format, and hence it is not parsed.</p>\n<p>In the following example, the JSON payload received is not in a compatible format, so no message is generated:</p>\n<table>\n<tbody>\n<tr>\n<td>code-block</td>\n<td>bash</td>\n</tr>\n<tr>\n<td>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">curl -X POST &lt;Incoming Webhook URL&gt; -H <span style=\"color: blue;\">\"Content-Type: application/json\"</span> -d '{</code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\"><span style=\"color: blue;\">\"product\": \"iPhone\", \"units\": \"1\", \"customer\": \"Adam\", \"price\": \"1000\"</span></code></span></p>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">}'</code></span></p>\n</td>\n<td> </td>\n</tr>\n</tbody>\n</table>\n<p>To receive messages via an incoming webhook from an app and service that uses an incompatible JSON format, you'll need to transform the data into a Flock-compatible format.</p>\n<ul>\n<li>First, make a note of the keys and values in the JSON payload.</li>\n<li>In the above example, the attributes are \"product\", \"units\", \"customer\", and \"price\" with the corresponding values being \"iPhone\", \"1\", \"Adam\", and \"1000\".</li>\n<li>Convert all the incompatible attributes to placeholder keys in the format: $(json.attribute)</li>\n<li>These placeholder keys will be replaced by the corresponding values in the message.</li>\n<li>String together the placeholder keys into an English sentence, and assign it to a key \"text\" or \"flockml\".</li>\n<li>Here is an example of the transformation template for the incompatible JSON payload:</li>\n</ul>\n<table>\n<tbody>\n<tr>\n<td>code-block</td>\n<td>bash</td>\n</tr>\n<tr>\n<td>\n<p><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\">{\"text\": \"$(json.customer) bought $(json.units) $(json.product) @ $$$(json.price)\"}</code></span><span class=\"wysiwyg-font-size-medium\"><code class=\"bash plain\"></code></span></p>\n</td>\n<td> </td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li class=\"wysiwyg-indent-1\">Go to your existing incoming webhook, click <em>Edit</em> and paste the transformation template under <em>Template Heading</em>.</li>\n</ul>\n<table>\n<tbody>\n<tr>\n<td>image-shadow</td>\n<td><img src=\"https://support.flock.com/hc/article_attachments/360025396533/Webhooks_Dev04.png\" alt=\"Webhooks_Dev04.png\"></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>The webhook will now generate messages in Flock such as \"Adam bought 1 iPhone @ $1000\".</li>\n</ul>\n<p> </p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 22.1427%;\">alert-warning</td>\n<td style=\"width: 77.8573%;\">The number of webhooks that can be created as per the current standard is 10 per user.</td>\n</tr>\n</tbody>\n</table>"}}