Build a QRCode API and Inventory Management System with Autocode and Airtable

栏目: IT技术 · 发布时间: 4年前

Build a QRCode API and Inventory Management System with Autocode and Airtable

May 27 ·7min read

If you use Airtable to keep an inventory of items in your warehouse, you can save time by scanning QR codes with your iPhone and quickly updating your Airtable base as you restock your shelves or check items in and out.

In this tutorial, we’ll learn to create QR Codes for every record in an Airtable base. You’ll be able to print QR Codes for each product and attach them to your inventory shelves for easy scanning and updating information on every record. :raised_hands|type_3:

Build a QRCode API and Inventory Management System with Autocode and Airtable

While Airtable’s iPhone app allows you to scan barcode numbers through your phone’s camera, it does not automatically generate unique barcodes every time a record is created.

What You’ll Need Beforehand

  • 1x Airtable free accountAirtable is a combination of a spreadsheet & database.
  • 1x Standard Library free account — A platform for building and deploying APIs, linking software tools, powering Slack apps, automating tasks, and more.

Part 1:We’ll learn how to build and publish a QRcode API service with Autocode

Part 2:We’ll use our QRCode API in an Airtable formula to automatically produce barcodes for each record (row) in Airtable.

Part 3:We’ll write a script to transform a bulk of image file URLs into image attachments in Airtable.

Part 1: How to Build a QRCode API with Autocode

Head on over and copy the QRCode template using this link:

https://autocode.stdlib.com/github/JanethL/QRCode/?filename=README.md

You will be prompted to sign in or create a free account. If you have a Standard Library account click Already Registered and sign in using your Standard Library credentials.

Give your project a unique name and select Start API Project from Github:

Build a QRCode API and Inventory Management System with Autocode and Airtable

Navigate through the functions folder on the left and select QRCode.js file.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Standard Library automatically generates HTTP endpoints (URLs) for each file.

This URL consists of

<username>.api.stdlib.com/<projectName>@environment/<endpointName> and it will be available after you deploy your project in the next steps.

For example:

A Brief Explanation:

The first lineof code imports the node QRcode NPM package . Autocode automatically adds dependencies to package.json file when importing NPM packages.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Build a QRCode API and Inventory Management System with Autocode and Airtable

Lines 3–7is a comment that serves as documentation and allows Standard Library to type check requests to our APIs. If a request does not supply a parameter with an expected type, it will return an error. You can learn more about the parameters and types here: https://github.com/FunctionScript/FunctionScript

This QRCode API endpoint has a parameter expecting a string that passes in a URL. It will return an HTTP Response as an object. The headers are set to {“Content-Type”: “image/png”} on line 22 and the body ( line 24 ) is the result we define on line 10.

Line 9is a function ( module.exports ) that will export our entire code found in lines 9–26 . Once you deploy your code, this function will be wrapped into an HTTP endpoint (API endpoint) and will be made available at:

https://<username>.api.stdlib.com/<ProjectName>@dev/<EndpointName>

Test Run the Code:

Before you deploy your API give it a test run. Find and select the Edit Test Event Payload button on the upper right.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Set the url to a site you’d like to generate a QRCode image for and click Save Payload. Payloads must be JSON formatted like this:

Build a QRCode API and Inventory Management System with Autocode and Airtable

When you select Run Test Event , you’ll see the QR code image result rendered by Autocode.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Take out your phone’s camera and test it out!

Build a QRCode API and Inventory Management System with Autocode and Airtable

:rocket: Ship your QRCode API Generator

You’re ready to deploy your QRCode API! Select Deploy in the bottom-left of the file manager.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Congrats! :tada:

Your QRCode service is live! You can see the documentation for your APIs by typing https://stdlib.com/@<username>/lib/<projectName>/dev/ in the browser.

Alternatively, find the manager button on the upper left and select View dev API Reference.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Your APIs docs will open up in a different tab. You can also test your API right from the docs by passing in any URL.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Part 2: Generate QRCodes for Every Row in Airtable using a Formula

You can easily create QRCode images for each item in an Airtable Product Inventory Management System. As a sample for this tutorial, we’ll use this inventory tracking template. Copy the template to your Airtable Workspace by clicking this link :point_down|type_3:

Right-click on any record in an Airtable to view the record URL.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Notice that all record URLs include: https://airtable.com/<TableID>/<ViewID>/<RecordID>

For Ex: https://airtable.com/tblHl8cNEZSLdibAJ/viweEDLt42xrPx17P/recTjaUlR9iEC9ayy

Build a QRCode API and Inventory Management System with Autocode and Airtable

We will use these record URLs in a formula to autogenerate QRCodes for every record using the API we built in Part 1.

Writing the Formula in Airtable

Step 1.

Create a new field and title it QRCodeLink select Formula for the field type.

Copy and paste your QRCode URL in the formula field, followed by ?url= .

Build a QRCode API and Inventory Management System with Autocode and Airtable

Here’s the result of the first part of the formula:

Build a QRCode API and Inventory Management System with Autocode and Airtable

Step 2:

Next, we’ll add a new function by first inserting an ampersand ( & ) as a separator. Then:

  • Add the ENCODE_URL_COMPONENT function followed by the URL to your Table which consists of "https://airtable.com/TavkeID/ViewID/" insert an ampersand ( & ) as a separator and add RECORD_ID() function to retrieve every row’s ID. Close off your function with a bracket ) .
  • Mine looks like this: 'https://janethl.api.stdlib.com/qrcode@dev/QRCode/?url=' & ENCODE_URL_COMPONENT("https://airtable.com/tblInrZQFQNQAuRce/viwfGWyw5TswcJHJk/" & RECORD_ID())

Build a QRCode API and Inventory Management System with Autocode and Airtable

Hit Save. Now every time you add a new record to your Airtable, a QRCode will be autogenerated for that record.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Part 3: Transfer Image File URLs to Attachments in Bulk with Autocode

You now have a link to the QRCode image for every row in Airtable.

Create a new Attachment field and title it QRCodeImage:

Build a QRCode API and Inventory Management System with Autocode and Airtable

Copy the code to transfer Image file URLs to attachments using this link:

https://autocode.stdlib.com/github/JanethL/Airtable-URL-To-Attachments/?filename=README.md

Name your project and select Start API Project from Github.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Navigate through the functions folder on the left and select QueryUpdate.js file.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Select the red Account Required button, which will prompt you to link an Airtable account.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Build a QRCode API and Inventory Management System with Autocode and Airtable

Select Link Resource and follow the instructions on the modal to retrieve your Airtable API Key and select Finish .

Build a QRCode API and Inventory Management System with Autocode and Airtable

Find and select your base and click Finish .

Build a QRCode API and Inventory Management System with Autocode and Airtable

Select Finished Linking.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Once you’ve finished Linking your accounts you need to add your base’s ID to line 12 and Line 28.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Locate your Base ID by clicking on the HELP tab on the upper right corner of your Base. Select API documentation.

Build a QRCode API and Inventory Management System with Autocode and Airtable

Copy the base id:

Build a QRCode API and Inventory Management System with Autocode and Airtable

Paste the base ID onto line 12 and line 28 in between the backtick quotes to set the value for baseId as seen in the screenshot:

Build a QRCode API and Inventory Management System with Autocode and Airtable

Hit Run Test Event and watch as your Airtable becomes populated by Autocode.

Build a QRCode API and Inventory Management System with Autocode and Airtable

That’s it!

You now have all the tools you need to build an Inventory Control System with Airtable and QRCode APIs on Standard Library. I hope you found this tutorial helpful. If you have any questions, jump into our support channels. Our team at Standard Library is ready to help.

Support


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

社群营销实战手册

社群营销实战手册

秋叶、邻三月、秦阳 / 人民邮电出版社 / 2018-1 / 69.00元

互联网正从“物以类聚”,走向“人以群分”的时代。秋叶等人的“社群营销”,并非单纯靠社群卖东西,而是建立一种中心化的、自行运转的生态,让“同好”们形成紧密的联系,创造出海量营销机会。 《社群营销实战手册 从社群运营到社群经济》共5章内容,从社群的定位、建立、扩张、变现、运营,到社群的生命周期延长、社群运营团队的打造和管理以及社群管理工具,大量干货秘笈一应俱全,并提供丰富的运营实战案例,全面解读社群的......一起来看看 《社群营销实战手册》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具