Publishable Keys
A publishable key starts with pk_. You can put it in a web page, for example in a barcode scanner on your website.
A secret API token must stay on your server. A publishable key is safe in the browser because of these limits:
- It can only call the barcode lookup routes.
- It only works from the domains that you allow.
- It has its own rate limits, and an optional daily cap.
Lookups with a publishable key use the API calls of your plan, like lookups with an API token.
Create a key
- Sign in and open Tokens in the dashboard.
- In Publishable Keys, create a key. Give it a name (3 to 32 characters).
- Add the allowed domains, one per line.
- Set the rate limits. Then copy the key.
You need an active plan or the free trial to create a publishable key. Each account can have up to 5 publishable keys.
Routes
A publishable key works on these routes only:
/api/v2/barcode/lookup/{barcode}
/api/v2/barcode/lookup/sku/{style_code}
/api/barcode/lookup/{barcode}
/api/barcode/lookup/sku/{style_code}The last two are the V1 routes. Any other route answers 403.
The key holds lookup-barcode, lookup-barcode-sku, or both. It can only hold an ability that your plan has.
See GET Lookup Barcode and GET Lookup Barcodes by SKU for the parameters and the answers.
Header
Authorization: Bearer pk_...Allowed domains
The browser sends the Origin header (or the Referer header) with each request. Barcodes.GG checks it against the allowed domains of the key.
A request without one of these headers answers 403. A publishable key does not work from a server or a script.
- Add up to 20 domains to a key.
- Without a scheme,
httpsis used.localhostand127.x.x.xusehttp. - Without a port, only the default port of the scheme matches. Add the port for local work, for example
localhost:5173. *.shop.comallows every subdomain ofshop.com, but notshop.comitself. Add both when you need both.- Paths are ignored.
Examples:
shop.com
https://*.shop.com
http://localhost:3000Rate limits
| Limit | Default | Range |
|---|---|---|
| Requests per minute for the key | 60 | 1 to 10,000 |
| Requests per minute for one visitor (IP address) | 10 | 1 to 10,000 |
| Daily cap for the key | No cap | 1 to 10,000,000 |
The daily cap stops a copied key from using all of your API calls. A request over a limit answers 429 with a Retry-After header.
Errors
| Status | Message |
|---|---|
401 | Invalid or expired publishable key. |
403 | Publishable keys can only be used for barcode lookups. Use an API key from your server for this endpoint. |
403 | Publishable keys can only be used from a website. No Origin or Referer header was sent. |
403 | This website (https://example.com) is not an allowed domain for this publishable key. |
429 | Rate limit reached for this publishable key, please wait and try again. |
429 | Rate limit reached, please wait and try again. |
429 | Daily limit reached for this publishable key. |
{
"error": true,
"message": "Invalid or expired publishable key."
}Use it with the scanner library
The @barcodesgg/scanner library scans barcodes with the camera. With a publishable key, it also looks up the product.