When we launched support for Webhook-triggered automations a few weeks ago I knew I wanted to create a fun demo to show off the feature. I had used the Tasker app for previous projects, so quickly reinstalled it and picked the first action and data point that struck my fancy. The result: I shake my phone and my latitude and longitude is logged to a Coda doc (see video here).
A week ago the official Coda account playfully pointed out the questionable utility of such an integration, while another user asked about the potential of scanning a barcode to a Coda doc. Challenge accepted!
I’ve had a few folks ask how I set it up, so here’s a breakdown:
Create the Coda doc
- Create a Coda doc to recieve the scanned barcodes.
- Add a table that includes a number column to receive the numerical value of the scanned value of the scanned barcode, called “Barcode”.
- Optionally add a Timestamp column which uses the formula
Now()
for new rows. - Optionally add an Image URL column to contain the rendered barcode, which uses a formula from the Barcode Pack. In my case I used
EAN13()
formula, but it depends on the type of barcode being scanned.
Copy this template to get my exact setup.
Create the webhook
- Add a new automation to the doc, using the trigger Webhook invoked.
- Click the Create API token button to get a new token.
- Copy the webhook URL and API token and place them somewhere you can access on your phone later (perhaps in the same Coda doc?).
The template doc above has the webhook added, but you’ll need to create your own API token.
Install the mobile apps
- Install Tasker (Android only).
- Install the AutoBarcode plugin for Tasker.
- Open both apps, granting them all of the permissions they need.
These apps are not free, and Android-only.
Configure Tasker
- In Tasker, create a new Profile selecting the source as Event > Plugin > AutoBarcode
- Click the pencil icon next to the Configuration to open the AutoBarcode settings for the event.
- Keep all of the defaults, and click the checkbox icon at the top to save the settings.
- Click the back arrow at the top to return to the profile.
- Add a new Task for the profile, and name it “Send to Coda”.
- Click the plus icon at the bottom to add a new action to the task, selecting Net > HTTP Request.
- Set the Method to POST.
- Set the URL to the webhook URL of the automation.
- In the Headers field, enter the value:
ReplacingAuthorization: Bearer <API token>
<API token>
with the API token you generated for your webhook. - In the Body field enter the following JSON message:
The structure of the JSON message can be whatever we want, as we’ll also be writing the formula to parse it later in the automation. The variable{ "barcode": "%abmessage" }
%abmessage
comes from the AutoBarcode plugin, and will be replaced with the numerical value of the scanned barcode. - Click the back arrow to save the action.
I’ve exported my Tasker configuration, which you can download here. After import you’ll need to edit it to set you own webhook URL and API token.
Finish the automation
- Returning to the Coda doc, in the Then section of the automation choose Add row.
- For the Table select the table created earlier.
- In Set values, set the Barcode column using the formula:
The fieldParseJSON(thisRow.[Step 1 Result], "barcode")
"barcode"
here must match the field created in the JSON body in Tasker. - Turn on the automation.
The template doc has this setup already as well.
Trying it out
- Add a new widget to your home screen, selecting AutoBarcode > AutoBarcode Scan.
- Click on the the widget to launch the barcode scanner.
- Scan a barcode.
I hope you find this useful, and let me know if you have any questions or feedback. Happy scanning!