Skip to main content

Read SKU.io data in Supabase

If you're building your own app on Supabase, you can read your SKU.io stock, products, costs, and sales orders there as SQL tables. Your app uses the numbers SKU.io already keeps, instead of working them out again. The connection is read-only: nothing your app does in Supabase changes SKU.io.

The setup scripts are in the open-source SKU.io for Postgres repository. You run them in your own Supabase project.

Before you begin​

  • You need a Supabase project, and permission to run SQL in it.
  • You need to be comfortable running SQL. If you'd rather not, see Get your SKU.io data into a spreadsheet or BI tool.
  • The token acts as you, so your SKU.io role has to allow you to see products, sales orders, and reports.
  • Each Supabase project reads one SKU.io account.

What you get​

TableWhat's in itRefreshes
sku.stockAvailable, allocated, on hold, on hand, in transit, backorder, and inbound, per product per warehouseEvery 5 minutes
sku.productsProducts with brand, supplier, costs, price, and stock totalsEvery hour
sku.costsUnit cost, average cost, supplier price, and stock value per productWith products
sku.sales_ordersSales orders from the last 90 days, without their linesEvery 15 minutes

Your queries read the copy in your own database. Only a refresh calls SKU.io. If a refresh can't read everything, it keeps the previous copy and records why.

Steps​

1. Create a read-only token​

In SKU.io, create a personal access token with these three scopes and no others:

  • products:read
  • orders:read
  • reports:read

Leave the IP allowlist empty unless your Supabase project has a fixed outbound address. Copy the token.

2. Store the token in Supabase Vault​

In Supabase, open the SQL Editor, paste your token into this line, and run it. Don't save the query.

select vault.create_secret('<your token>', 'sku_api_token');

3. Run the install script​

  1. Open sql/01_install.sql and copy it into the SQL Editor.
  2. Replace YOUR-SUBDOMAIN with the part before .sku.io in your SKU.io address. For https://acme.sku.io, that's acme.
  3. Run the whole script.

It loads the tables and finishes with a list of each table, how many rows it has, and whether the load worked.

4. Schedule the refreshes​

Run sql/02_schedule.sql the same way. To see how fresh each table is at any time, run:

select * from sku.refresh_status;

5. Query your data​

select sku, warehouse_name, available, inbound
from sku.stock
where available < 10
order by available;

Get changes as they happen​

To store shipments and stock changes when SKU.io sends them, use the webhook function in the repository. Stock changes are sent in 30-second batches. It checks each delivery's signature and stores it once.

  1. Follow Webhooks in the repository to add the function to your project.
  2. In SKU.io, subscribe to webhooks for Stock Level Changed and Shipment Sent, with your function's address as the Target URL.
  3. Click Send test delivery on each one.

Decide who can see the tables​

Only your server code can read the tables at first. Anything you show to signed-in users has to be a view you create on purpose. The repository has an example. Think about costs before you share them: everyone who can read a view sees every row in it.

Webhook deliveries are stored as SKU.io sends them, which for shipments includes the customer's name and email.

If a refresh fails​

Run the status query from step 4 and read the error column.

The error saysWhat to do
HTTP 401The token is wrong, expired, or revoked. Create a new one and replace it in Vault.
HTTP 403The token is missing a scope, or its IP allowlist blocks Supabase. See Fix a 403 from your API token.
read … of … rowsRecords were removed while the refresh was reading. The next refresh tries again.

Next steps​

Last verified: