<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Yusuf Musleh</title>
    <description>The latest articles on Forem by Yusuf Musleh (@ymusleh).</description>
    <link>https://forem.com/ymusleh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F455033%2F0f047368-a4f2-432f-aaf9-1f29849b4b03.png</url>
      <title>Forem: Yusuf Musleh</title>
      <link>https://forem.com/ymusleh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ymusleh"/>
    <language>en</language>
    <item>
      <title>How to handle Webflow Multi-Reference Fields in Form Submissions</title>
      <dc:creator>Yusuf Musleh</dc:creator>
      <pubDate>Sat, 28 Nov 2020 04:59:46 +0000</pubDate>
      <link>https://forem.com/ymusleh/how-to-handle-webflow-multi-reference-fields-in-form-submissions-1o18</link>
      <guid>https://forem.com/ymusleh/how-to-handle-webflow-multi-reference-fields-in-form-submissions-1o18</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Creating a &lt;strong&gt;Collection Item&lt;/strong&gt; in a Webflow CMS when a user submits a form is a common use case for a Webflow site. There have been multiple ways to achieve this using the many low-code/no-code automation tools. However, historically there's been a common complaint amongst many makers; that things get tricky when the form contains &lt;strong&gt;multi-reference&lt;/strong&gt; fields because of the way Webflow formats them in the form submission event data.&lt;/p&gt;

&lt;p&gt;In this article I'll walk you through solving this problem using Autocode. You can see it in action right away by performing form submissions from a sample Webflow site and see collection items created in the CMS when forms are submitted.&lt;/p&gt;

&lt;p&gt;First, you need to clone the &lt;a href="https://webflow.com/website/my-blog-form" rel="noopener noreferrer"&gt;Webflow site by clicking here, then pressing the &lt;strong&gt;Clone&lt;/strong&gt; button on the top right&lt;/a&gt; to copy the sample blog form site to your own Webflow account. Then, you need to map the values of each category field in the form to the corresponding Category item ID and publish the site. (If you're not sure how to get the category IDs, check the &lt;strong&gt;How It Works&lt;/strong&gt; section below).&lt;/p&gt;

&lt;p&gt;Once you've cloned and published the Webflow site, &lt;a href="https://autocode.com/app/webflow/webflow-multi-reference-form/" rel="noopener noreferrer"&gt;click here to open the starter app in Autocode&lt;/a&gt;. You can checkout the source code if you'd like, then install the app to your Autocode account. You'll then be asked to link your Webflow site, simply follow the instructions to do so. Next, you'll need to set the &lt;code&gt;COLLECTION_ID&lt;/code&gt; environment variable for the &lt;strong&gt;Blog Posts&lt;/strong&gt; collection in the site you cloned. (If you're not sure how to get the collection id, check the &lt;strong&gt;How It Works&lt;/strong&gt; section below).&lt;/p&gt;

&lt;p&gt;After that, you're good to go! Once the app finishes installing and deploying, you can go to your Blog Site and submit a form selecting some &lt;strong&gt;Categories&lt;/strong&gt; (multi-reference fields). A new blog post will appear in the CMS referencing the correct categories that were selected!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq09319enisc94yqwhkxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq09319enisc94yqwhkxc.png" alt="Webflow Form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsewe6ihwxg1av3t4hfyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsewe6ihwxg1av3t4hfyx.png" alt="Webflow CMS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://webflow.com/" rel="noopener noreferrer"&gt;Webflow&lt;/a&gt; is a great tool for building websites and e-commerce stores with little to no code required. Utilizing their powerful drag &amp;amp; drop UI builder bundled with their CMS, means you can go from an idea to a live website in a very short period of time. It has become a very common tool in the arsenal of many makers.&lt;/p&gt;

&lt;p&gt;One of common use cases or flows many people build on Webflow is a form that stores submissions in the Webflow CMS. In other words, being able to create a &lt;strong&gt;Collection Item&lt;/strong&gt; when a user submits a response to a form on the site. There have been multiple ways to achieve this using the many low-code/no-code automation tools. However, historically there's been a common complaint amongst many makers; that things get tricky when the form contains &lt;strong&gt;multi-reference&lt;/strong&gt; fields.&lt;/p&gt;

&lt;p&gt;Say you have a blogging website that allows users to create blog posts by submitting a form on your site. In that form you allow your users to tag their blog posts with different topic categories. These categories are fetched from a collection you created in your Webflow CMS. These categories are represented as a &lt;strong&gt;multi-reference&lt;/strong&gt; field in your Blog Posts.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Problem
&lt;/h4&gt;

&lt;p&gt;Generally the automation of this process involves 2 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Listening to when a form is submitted&lt;/li&gt;
&lt;li&gt;Creating a new Collection Item using the data from the submitted form&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While most tools do a great job handling the first step, listening to form submissions from Webflow. Passing in that data directly to the default Webflow &lt;code&gt;Create Collection Item&lt;/code&gt; connector/module would usually fail when multiple items are selected in the multi-reference field. This is because of how Webflow represents multi-reference field data in the event object and what the connector/module expects.&lt;/p&gt;

&lt;p&gt;Below is sample payload that Webflow sends when a form is submitted (in this case &lt;code&gt;Categories&lt;/code&gt; is the multi-reference field):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"d"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2020-08-26T16:29:54.226Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"[SOME_TITLE]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"[SOME_CONTENT]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000001,000000000000000000000002,000000000000000000000003"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"FORM_NAME"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"site"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000000"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the data in &lt;code&gt;Categories&lt;/code&gt; is a comma-separated string instead of an array. If you try to pass this in directly to the connector/module that creates a collection item it would consider the whole string as a single ID and fail to identify a &lt;code&gt;Category&lt;/code&gt; with that ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[400] ValidationError: Validation Failure Referenced item not found: categories
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because of this, many folks handle this by stitching together multiple connectors/module to modify the data, and manually make API calls to Webflow to solve this problem.&lt;/p&gt;

&lt;p&gt;In this article, I'll show you how to easily handle this using Autocode. A Node.js API development platform and online code editor/IDE with built-in autocomplete, that handles Webflow's authentication, listening to form submission events and creation of collection items.&lt;/p&gt;

&lt;p&gt;All you need to follow along is a Webflow account, with this sample &lt;a href="https://webflow.com/website/my-blog-form" rel="noopener noreferrer"&gt;blog site&lt;/a&gt; cloned, and a free Autocode account.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How It Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Before you start, you'd need to setup clone and setup the Webflow site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Clone&lt;/strong&gt; button on the top right corner of this &lt;a href="https://webflow.com/website/my-blog-form" rel="noopener noreferrer"&gt;page&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Map each of the category fields in the form to their corresponding Category Item IDs
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxzwkxzyen0l1u5od4bft.png" alt="Mapping category IDs"&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the category IDs, by navigating to the CMS, then clicking on each of the &lt;strong&gt;Category&lt;/strong&gt; Items in the &lt;strong&gt;Categories Collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1a3206r7pa0jqrc64fvq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1a3206r7pa0jqrc64fvq.png" alt="Categories Collection Item IDs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Publish the cloned site to be able to make form submissions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkqkuyotl31e8nnjezsg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkqkuyotl31e8nnjezsg1.png" alt="Publish Webflow Site"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Let's Get Started&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When you link your Webflow site to your &lt;a href="https://autocode.com/app/webflow/webflow-multi-reference-form/" rel="noopener noreferrer"&gt;app&lt;/a&gt;, Autocode takes care of the Authentication, creation and validation of webhooks to listen to form submission events, and making API calls to Webflow.&lt;/p&gt;

&lt;p&gt;This app listens to all &lt;strong&gt;form_submission&lt;/strong&gt; events coming from the linked Webflow site by default, you'll notice a wild card &lt;code&gt;*&lt;/code&gt; is specified in the &lt;strong&gt;form_name&lt;/strong&gt; field in the event handler. If you'd like to specify a certain form to listen to submission events from, you can add a new &lt;strong&gt;form_submission&lt;/strong&gt; event handler and set the &lt;strong&gt;form_name&lt;/strong&gt; to your specific form's name defined in the Webflow designer.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Diving into some code&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The event handler is simply an exported JavaScript function that takes in a parameter called &lt;code&gt;event&lt;/code&gt; that represents the event coming in from Webflow. This function runs every time a form is submitted on your site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)({&lt;/span&gt;&lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STDLIB_SECRET_TOKEN&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="cm"&gt;/**
* An HTTP endpoint that acts as a webhook for Webflow form_submission event
* @param {object} event
* @returns {object} result Your return value
*/&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// event handler logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We include all the logic that we would like to run whenever we get a new event, i.e. when a form is submitted on our site. The general structure of the &lt;code&gt;event&lt;/code&gt; parameter object is as we described earlier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"d"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2020-08-26T16:29:54.226Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"[SOME_TITLE]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"[SOME_CONTENT]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000001,000000000000000000000002,000000000000000000000003"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"FORM_NAME"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"site"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"000000000000000000000000"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Creating a Collection Item with Multi-Reference fields
&lt;/h5&gt;

&lt;p&gt;Now that we know how the event handler is setup and what the event object looks like, let's take a look at creating new collection items with these multi-reference fields.&lt;/p&gt;

&lt;p&gt;When we get a new form submission we first check if the multi-reference field (in our case &lt;code&gt;Categories&lt;/code&gt;) is present in the &lt;code&gt;data&lt;/code&gt; object of the event. If it is, simply split it on the commas &lt;code&gt;,&lt;/code&gt; to get a list of IDs, otherwise set it to an empty list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;categoryIDs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Categories&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Based on the example event object mentioned earlier, it will convert it to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;000000000000000000000001&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;000000000000000000000002&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;000000000000000000000003&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You'd need to do this for every multi-refernce field you have in order to pass it in the endpoint below to create the collection item.&lt;/p&gt;

&lt;p&gt;Next, to create the collection item in Webflow we utilize the&lt;br&gt;
&lt;a href="https://autocode.com/lib/webflow/collections/#items-create" rel="noopener noreferrer"&gt;collections.items.create&lt;/a&gt; API endpoint from &lt;a href="https://autocode.com/lib/" rel="noopener noreferrer"&gt;Autocode's Standard Library&lt;/a&gt;, and pass in the required fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;lib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@1.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;collection_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;COLLECTION_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;categories&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;categoryIDs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;_archived&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;_draft&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;live&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;collection_id&lt;/code&gt;: is the ID of the collection in the CMS to create the item in. To get that ID, navigate to the CMS tab in the Webflow designer of your site, then click
on the settings button for the Collection (in this case &lt;strong&gt;Blog Posts&lt;/strong&gt;) and it should be there&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuo8resxvuv8kl74ioz4y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuo8resxvuv8kl74ioz4y.png" alt="Webflow Collection ID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;fields&lt;/code&gt;: the fields of the item that will be created. Notice how we passed in the &lt;code&gt;categoryIDs&lt;/code&gt; list to the &lt;code&gt;categories&lt;/code&gt; field to reference the categories that the blog post maps to in Webflow&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;live&lt;/code&gt;: whether or not the item should be published to the live site when created&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once that endpoint is called, the new item will be created and appear in the &lt;strong&gt;Blog Posts&lt;/strong&gt; CMS in Webflow. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuwydpuqz0pikg0dphxxd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuwydpuqz0pikg0dphxxd.png" alt="Webflow CMS Collection Item"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Tying it all together
&lt;/h5&gt;

&lt;p&gt;The final result of the event handler should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)({&lt;/span&gt;&lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STDLIB_SECRET_TOKEN&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="cm"&gt;/**
* An HTTP endpoint that acts as a webhook for Webflow form_submission event
* @param {object} event
* @returns {object} result Your return value
*/&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;categoryIDs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Categories&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;lib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@1.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;collection_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;COLLECTION_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;categories&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;categoryIDs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;_archived&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;_draft&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;live&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;That's It!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Thank you for checking out this post. If you have any questions or feedback please feel free to join our community Slack channel. You can get an invite from the &lt;strong&gt;Community&lt;/strong&gt; Tab in the top bar of the &lt;a href="https://autocode.com" rel="noopener noreferrer"&gt;Autocode website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also follow the Autocode team on Twitter for updates &lt;a href="https://twitter.com/AutocodeHQ" rel="noopener noreferrer"&gt;@AutocodeHQ&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webflow</category>
      <category>autocode</category>
      <category>api</category>
      <category>automation</category>
    </item>
    <item>
      <title>Setup a Custom Webhook URL in 30 Seconds with Autocode</title>
      <dc:creator>Yusuf Musleh</dc:creator>
      <pubDate>Wed, 19 Aug 2020 06:44:35 +0000</pubDate>
      <link>https://forem.com/ymusleh/setup-a-custom-webhook-url-in-30-seconds-with-autocode-3ce9</link>
      <guid>https://forem.com/ymusleh/setup-a-custom-webhook-url-in-30-seconds-with-autocode-3ce9</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;TLDR (30s)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To quickly get your own customizable Webhook URL, simply &lt;strong&gt;Fork&lt;/strong&gt; this &lt;a href="https://autocode.com/src/ymusleh/my-webhook/"&gt;Source in Autocode&lt;/a&gt;. You can change the name of the project if you'd like, as it's reflected in the webhook URL that's generated. &lt;/p&gt;

&lt;p&gt;Once you've created the Fork you'll be brought into the Autocode editor. Click on the blue Deploy button at the bottom left corner of the editor. Once it's deployed, open the &lt;code&gt;functions/__main__.js&lt;/code&gt; file to view the live Webhook URL at the bottom of the editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cP1WPXdn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/deploy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cP1WPXdn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/deploy.png" alt="deploy webhook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! You can add whatever custom handling logic you'd like to the webhook at anytime, and simply click deploy again!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Make sure you include the &lt;code&gt;/&lt;/code&gt; at the end of the url otherwise it will be redirected and the payload will be dropped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;--request&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--url&lt;/span&gt; https://YOUR_USERNAME.api.stdlib.com/my-webhook@dev/ &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--header&lt;/span&gt; &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--data&lt;/span&gt; &lt;span class="s1"&gt;'{
  "some_data": "This is sample data",
  "more_data": "More sample data"
}'&lt;/span&gt;

&lt;span class="c"&gt;# OR&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;--request&lt;/span&gt; GET &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--url&lt;/span&gt; &lt;span class="s1"&gt;'https://YOUR_USERNAME.api.stdlib.com/my-webhook@dev/?some_data=%22This%20is%20sample%20data%22&amp;amp;more_data=%22More%20sample%20data%22'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DWGkVwCe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/example-curl-request.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DWGkVwCe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/example-curl-request.png" alt="logs"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Often when working on projects that involve integrating different tools together or syncing data between different services, you may find yourself utilizing &lt;strong&gt;webhooks&lt;/strong&gt;. A lot of tools/services allow you to set a webhook URL that they can then push data to based on some triggers. The webhook server behind that URL can then perform custom logic with that data.&lt;/p&gt;

&lt;p&gt;Sounds pretty straightforward right? However, you'll realize you have to provision a new server, develop and deploy a web app, and worry about other administrative tasks such as maintenance and scalability. Not to mention, every time you want to make changes or test different payloads, you'd need to go through the deployment process again.&lt;/p&gt;

&lt;p&gt;This adds a lot of hurdles just to perform a simple task of receiving and handling data from an external service.&lt;/p&gt;

&lt;p&gt;We get a lot of questions about setting up webhooks at &lt;a href="https://autocode.com/"&gt;Autocode&lt;/a&gt;, and I think it's the easiest way to get started and have a live webhook URL in (literally) seconds. I built a &lt;a href="https://autocode.com/src/ymusleh/my-webhook/"&gt;Source in Autocode&lt;/a&gt; that you can simply fork and deploy to get your own webhook URL in no time!&lt;/p&gt;

&lt;p&gt;Your webhook is deployed on top of serverless technology. That means it will scale for you without any need for administrative efforts on your end.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How It Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When your webhook is deployed on Autocode, the endpoint listens to incoming requests. It accepts both &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; requests. The parameters passed in from either the request body or querystrings are parsed out and included in the &lt;code&gt;context.params&lt;/code&gt; object. &lt;code&gt;context&lt;/code&gt; is a magic parameter that we populate automatically. It must be the last parameter in the list of parameters you define in your function signature. You can access the headers or the actual request body and other useful data from within the &lt;code&gt;context&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
* An HTTP endpoint that acts as a webhook for HTTP(S) request event
* @returns {object} result Your return value
*/&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;params:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;headers:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also pass in named parameters with type checking included out of the box based on the &lt;a href="https://github.com/functionscript/functionscript"&gt;FunctionScript&lt;/a&gt; specification. Simply include the named parameter as an argument in the function and update the comment above the function defining the name and type of that parameter it should expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
* An HTTP endpoint that acts as a webhook for HTTP(S) request event
* @param {string} name
* @param {number} age 
* @returns {object} result Your return value
*/&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;params:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;headers:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Testing with Payloads&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can test your webhook URL before deploying it from within the Autocode editor.&lt;/p&gt;

&lt;p&gt;Press on the &lt;strong&gt;Edit Test Event Payload&lt;/strong&gt; at the top of the endpoint file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--idGYja0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/edit-payload-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--idGYja0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/edit-payload-button.png" alt="edit test payload"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That will open up the payload editor where you can enter a JSON formatted payload for testing:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0eWsY5NM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/payload-editor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0eWsY5NM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/payload-editor.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've finished setting a test payload and saved it, click on the green &lt;strong&gt;Run Test Event&lt;/strong&gt; button at the bottom right corner of the editor. That will then open up a console displaying any logs or errors you may have:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xpzfxCYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/run-test-event-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xpzfxCYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/run-test-event-button.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l2SLrA9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/testing-payload.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l2SLrA9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/testing-payload.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Deploying your Webhook&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you're ready to deploy your webhook URL and start listening to incoming events, all you need to do is press on the blue &lt;strong&gt;Deploy&lt;/strong&gt; button at the bottom left corner of the editor:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cP1WPXdn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/deploy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cP1WPXdn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://du2ha4sdmc25q.cloudfront.net/ymusleh/my-webhook/src_8ehAnpfNgm3xzLYbTqJZWMtqXzt1zuMqBUNM/readme/deploy.png" alt="deploy webhook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once it's deployed, the URL displayed is now ready to handle events from any external service. You can also view real time logs by clicking on the View Logs button in the same corner of the editor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Make sure you include the &lt;code&gt;/&lt;/code&gt; at the end of the URL otherwise it will be redirected and the payload will be dropped.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;That's It!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Thanks for checking out this post! Hope it helped, if you have any questions please feel free to reach out to me at &lt;a href="mailto:yusuf@autocode.com"&gt;yusuf@autocode.com&lt;/a&gt;. I'd love to hear about what you're building! You can also follow the Autocode team on Twitter for more updates &lt;a href="https://twitter.com/autocodehq"&gt;@AutocodeHQ&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Yusuf is a software engineer at &lt;a href="https://autocode.com/"&gt;Autocode&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>webhook</category>
      <category>api</category>
    </item>
  </channel>
</rss>
