Build a QRCode Inventory Management System with Autocode and Airtable
Tags: airtable, automation, api, javascript
Published: 2022-09-26 16:42:01

---
title: Build a QRCode Inventory Management System with Autocode and Airtable
published: true
description: In this tutorial, we’ll learn to build a system that automatically creates 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.
canonical_url: https://autocode.com/autocode/threads/build-a-qrcode-inventory-management-system-with-autocode-and-airtable-tutorial-ffb392d9/?utm_source=dev.to&utm_medium=tutorial&utm_campaign=solutions
tags: Airtable, Automation, Api, Javascript
# cover_image: https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_01.png 
# Use a ratio of 100:42 for best results.
---
If you use [Airtable](https://airtable.com/templates/local-business/expDrHGuyjSQlrKTq/inventory-tracking) 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 build a system that automatically creates 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.

![Product Inventory Tracker in Airtable](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_01.png)

### Part 1: Generate QRCodes for every row in Airtable using a formula
We’ll use the [QRCode](https://autocode.com/qrcode/api/generate/#__main__) API in an Airtable formula to automatically produce barcodes for each record (row) in Airtable.

### Part 2: Transform image file URLs to attachments in bulk with Autocode
We’ll write a script to transform a bulk of image file URLs into image attachments in Airtable.

Let’s get started!

## Part 1: 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 👇🏼

https://airtable.com/templates/local-business/expDrHGuyjSQlrKTq/inventory-tracking

Right-click on any record in an Airtable to view the record URL.
![Right-click on any record in an Airtable to view the record URL](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_02.png)

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

For Ex: https://airtable.com/appYf6XDJS4EtYfP1/tbl5CBRYJFvT3VCif/viwCV6qE9IazFasPl/rechADzwWPVMsMBg4

We will use these record URLs in a formula to autogenerate QRCodes for every record using an API service hosted on Autocode:

https://autocode.com/qrcode/api/generate/#__main__

Try it out by inputting some `text` and `errorCorrectionLevel`. Press **Run** and take out your phone to scan the QrCode. 

![QRCode API service Docs](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_03.png)

Great! We can use this QRCode service that we can use to automatically generate QRcodes for every record in our Airtable.  

## Writing the Formula in Airtable
Create a new field and title it `QRCodeLink` (field names to to be exact) select `Formula` for the field type. 

Copy and paste the QRCode URL in the formula field, followed by `?text=`.
Like so: `https://qrcode.api.stdlib.com/generate@0.0.3/?text=`

![Formula field type](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_04.png)
## Step 2:

Next, we’ll add a new function by first inserting an ampersand (&amp;) as a separator. Then:
- Add the `ENCODE_URL_COMPONENT(` function followed by the URL to your Table which consists of 
  "https://airtable.com/TableID/ViewID/" insert an ampersand (&amp;) as a separator and add `RECORD_ID()` 
  function to retrieve every row’s ID. Don’t forget to close off your function with a bracket `)` .
  Add another ampersand (&amp;) separator and add the additional parameter `'?errorCorrectionLevel=Medium'`
  
- Mine looks like this: 'https://qrcode.api.stdlib.com/generate@0.0.3/?text=' &amp; ENCODE_URL_COMPONENT("https://airtable.com/tbl5CBRYJFvT3VCif/viwCV6qE9IazFasPl/" &amp; RECORD_ID()) &amp; '?errorCorrectionLevel=Medium'

![Formula field type in Airtable](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_05.png)

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

![Airtable base](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_06.png)

### Part 2: Transform 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 exactly like so: `QRCodeImage`:

![Attachment field in Airtable base](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_07.png)

We now need to write a script on Autocode to transform our QrCode links to image attachments. Head on over to your [Autocode dashboard](https://autocode.com/dashboard/) and sign in or create an account. 

Select ***New Web Service*** and give the project a name. 

![New Web Service](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_08.png)

You will be routed to the `__main___.js` file for your project. Delete the auto generated code and paste the following code:

```javascript
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});

module.exports = async () =&gt; {
  let result = {airtable: {}};

console.log(`Running [Airtable → Select Records by querying a Base]...`);
  result.airtable.selectQueryResult = await lib.airtable.query['@0.5.2'].select({
    baseId: `&lt; Insert BaseId Here &gt;`,
    table: `Product Inventory`,
    where: [
      {
        'QRCodeImage__is_null': true
      }
    ],
    limit: {
      'count': 0,
      'offset': 0
    }
  });
  console.log(`Running [Airtable → Update Records by querying a Base]...`);
  for (var i = 0; i &lt; result.airtable.selectQueryResult.rows.length; i++) {
  await lib.airtable.query['@0.5.2'].update({
    baseId: `&lt;Insert BaseID Here&gt;`,
    table: `Product Inventory`,
    where: [
      { 
      'Product ID': `${result.airtable.selectQueryResult.rows[i].fields['Product ID']}`
      }
      ],
    limit: {
      'count': 0,
      'offset': 0
    },
    fields: {
      'QRCodeImage': [ {"url": `${result.airtable.selectQueryResult.rows[i].fields['QRCodeLink']}`}]
      },
    typecast: false
  });
  }
  return result;
};

```
Press **Save** and select the red **Account Required button**, which will prompt you to link an Airtable account.
![Code pasted onto Autocode IDE as a web service](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_09.png)

Select **Link** then **Link Resource** and follow the instructions on the modal to retrieve your Airtable API Key and select Finish.
![Linked Airtable Account](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_10.png)
Once you’ve finished Linking your accounts you need to add your base’s ID to line 12 and Line 28.

![Help tab on Airtable](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_11.png)
Locate your Base ID by clicking on the **HELP** tab on the upper right corner of your Base. Select API documentation.

![Locate your Base ID by clicking on the **HELP** tab on the upper right corner of your Airtable Base](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_12.png)

Copy the base id:
![Copy airtable base id](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_13.png)

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:

![Paste base id into Autocode project](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_14.png)

Finally up your timeout to 30,000 ms. By default it is set to 10,000 ms. 

![Timeout feature on Autocode IDE](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QrCode_16.png)

If you have a large amount of records, you may need to run this script a couple of times to complete transfering all links to attachemts. 
Hit Run Test Event and watch as your Airtable becomes populated by Autocode.

![Product Inventory Tracker in Airtable](https://janethl.public.files.stdlib.com/_stdlib/provider/autocode/images/2022-09-22/QRCode_15.png)

## That’s it! 🤗
You now have all the tools you need to build an inventory control system with Airtable and [QRCode APIs](https://autocode.com/qrcode/api/generate/#__main__) on Autocode. I hope you found this tutorial helpful. If you have any questions, jump into our [Discord support channels](https://discord.com/invite/UjJAmdN3uZ). Our team at Autocode is ready to help.