4QR API for business
Create, change and track 4QR codes from your own systems: a website, a CRM, a spreadsheet script, Zapier. This guide is for developers. Every example is a plain curl command. The full reference is the OpenAPI contract, available from support@4qr.app on request (if this guide and the contract ever disagree, the contract wins).
- Base URL:
https://api.4qr.app/v1. HTTPS only, JSON only (UTF-8). - A forever code is a short link
https://4qr.app/<slug>printed inside the QR image. Aurlcode redirects to your link; the other six types (contact,wifi,phone,sms,email,text) open a small code page. You can change where a code leads at any time; the printed QR stays the same. - Each new forever code spends one credit. Credits are bought only in the 4QR iPhone app (one code — $1, or a pack of 10). The API spends credits; it can't buy them.
- Codes are never deleted. Only the service can disable a code (unsafe link, abuse reports).
Contents
- Get an API key
- Authentication
- Quick start
- Create a code
- List and read codes
- Change a code
- Stats
- Many codes at once
- Errors
- Limits and Retry-After
- Good practice
1. Get an API key
- In the 4QR app open Settings → API keys, tap New key, name it so you'll recognise it later (
Website,Zapier, 1–64 characters) and tap Create key. - Copy the key right away. It looks like
fqr_live_followed by 43 letters and digits (52 characters in total). It is shown only once: the service keeps only a fingerprint of it and can't show it again. If you lose it, revoke it and create a new one. - Keep the key on your server, in a secret store. Never put it in a web page, a mobile app or a public repository.
The app lists your active keys by name and their first 13 characters (fqr_live_Ab3x), with the time each was last used (updated at most once an hour). You can have up to 10 active keys. Revoke a key in the same screen: it stops working with the next request; the codes it created keep working.
Managing keys and buying credits is possible only in the app. An API key gets 403 forbidden_for_api_key on those operations.
2. Authentication
Send the key in the Authorization header of every request:
Authorization: Bearer fqr_live_…
The examples below read it from an environment variable:
export API_BASE=https://api.4qr.app/v1
export API_KEY='<your key>'
An API key can call:
| Operation | What |
|---|---|
GET /credits |
credits left |
POST /codes |
create a code |
GET /codes |
list your codes |
GET /codes/{id} |
one code |
PATCH /codes/{id} |
change a code's name or data |
GET /codes/{id}/stats |
scans by day, country and device |
POST /codes/batch |
create up to 500 codes at once |
A key acts for the owner who created it: it spends the owner's credits, its codes are the owner's codes and appear in the app, and it sees all the owner's codes — including those made in the app or with another key.
A missing or malformed header, an unknown key and a revoked key all get the same 401 unauthorized.
3. Quick start
Check the balance, create a code, print its short link:
curl -sS "$API_BASE/credits" -H "Authorization: Bearer $API_KEY"
# {"credits":5}
CODE=$(curl -sS -X POST "$API_BASE/codes" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"type":"url","name":"Café menu","data":{"url":"https://joescafe.example/menu"}}')
echo "$CODE"
CODE_ID=$(echo "$CODE" | jq -r .id)
echo "$CODE" | jq -r .short_url
# https://4qr.app/Xk7pQ2m
Put short_url into the QR image exactly as returned (any QR generator will do; the app makes print-ready images). Don't build the link yourself.
4. Create a code
POST /codes — spends one credit. Body: type, name, data, all three required, no other fields.
type— one ofurl,contact,wifi,phone,sms,email,text. It never changes later.name— your label for the code, 1–100 characters, one line. Only you see it: it's not shown to people who scan the code.data— the content, by type (below).- Header
Idempotency-Key— required: 16–64 charactersA-Z a-z 0-9 _ -, a new UUID per code you mean to create. See Retries.
curl -sS -X POST "$API_BASE/codes" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7b0c1e4e-3f7a-4c1e-9a55-2d3c4b5a6f70" \
-d '{
"type": "url",
"name": "Café menu",
"data": {
"url": "https://joescafe.example/menu",
"utm": {"source": "qr", "medium": "print", "campaign": "Café menu"}
}
}'
Answer 201 Created:
{
"id": 1042,
"slug": "Xk7pQ2m",
"short_url": "https://4qr.app/Xk7pQ2m",
"type": "url",
"name": "Café menu",
"data": {
"url": "https://joescafe.example/menu",
"utm": {"source": "qr", "medium": "print", "campaign": "Café menu"}
},
"target_url": "https://joescafe.example/menu?utm_source=qr&utm_medium=print&utm_campaign=Caf%C3%A9%20menu",
"status": "active",
"disabled_reason": null,
"frozen_at": null,
"batch": null,
"scans_total": 0,
"created_at": "2026-10-11T14:05:09Z",
"updated_at": "2026-10-11T14:05:09Z"
}
The short link works right after 201.
data by type
type |
Required | Optional | Example data |
|---|---|---|---|
url |
url — http:// or https://, ≤ 2048 |
utm — source, medium, campaign, all three, each ≤ 100 |
{"url":"https://joescafe.example/menu"} |
contact |
phones (0–3), emails (0–3) and at least one of first_name, last_name, org |
title, website, address |
{"first_name":"Maria","last_name":"Lopez","org":"Joe's Café","phones":["+1 415 555 0134"],"emails":["maria@joescafe.example"]} |
wifi |
ssid (≤ 32 bytes), security (WPA, WEP, nopass), hidden |
password (required for WPA and WEP, absent for nopass) |
{"ssid":"JoesCafe-Guest","password":"latte-art-2026","security":"WPA","hidden":false} |
phone |
number — digits, spaces, + ( ) - ., 3–20 digits |
— | {"number":"+1 415 555 0134"} |
sms |
number (as phone) |
message ≤ 500 |
{"number":"+1 415 555 0134","message":"Table 4, please"} |
email |
to — one address |
subject ≤ 150, body ≤ 500 |
{"to":"hello@joescafe.example","subject":"Feedback"} |
text |
text ≤ 1000 |
— | {"text":"Back in 10 minutes."} |
Rules for every type (each type has an exact JSON Schema in the OpenAPI contract):
- Lengths are in Unicode characters (code points), except
ssid, which is in UTF-8 bytes. - Leave an optional field out instead of sending
""ornull; empty and blank strings are errors. - Unknown fields are errors.
- Multi-line text is allowed only in
text,message,bodyandaddress; control characters and text-direction overrides are not allowed anywhere. - A
urlcode redirects totarget_url: yoururlplusutm_source,utm_medium,utm_campaignwhenutmis set; the result must also fit in 2048 characters. - Every link (
urlofurl,websiteofcontact) is checked against Google Web Risk. A link on the unsafe list is refused with403 url_blocked. If the check itself is unavailable, the code is created and the link is checked again later. - Refused links are limited: 50 link checks in any 24 hours that created nothing (
url_blocked, single codes and batches together) per owner; a link stops counting once you create a code with it. A link you checked in the last 24 hours is not checked again: a refused link sent again is refused at once, a safe one passes without a new check and doesn't count for that request. After 50, creating a code with a link that needs a new check gets429untilRetry-After(1if it is your other create requests still running that hold the limit); codes without links are not affected (see Limits).
Errors of this operation: 400 (body, Idempotency-Key), 401, 402 no_credits, 403 url_blocked, 413 payload_too_large (body over 64 KiB), 429, 500 — see Errors. Any error creates nothing and spends nothing.
5. List and read codes
GET /codes — all your codes, any status, newest first, up to limit per page (1–500, default 100). When there are more, next_cursor is a string: pass it as cursor to get the next page. On the last page next_cursor is null.
curl -sS "$API_BASE/codes?limit=1" -H "Authorization: Bearer $API_KEY"
{
"codes": [
{"id": 1043, "slug": "Rb4tNw8", "short_url": "https://4qr.app/Rb4tNw8", "type": "url", "name": "Café menu", "…": "…"}
],
"next_cursor": "<opaque string>"
}
All pages, one after another:
CURSOR=""
while :; do
PAGE=$(curl -sS "$API_BASE/codes?limit=500${CURSOR:+&cursor=$CURSOR}" -H "Authorization: Bearer $API_KEY")
echo "$PAGE" | jq -r '.codes[] | "\(.id)\t\(.short_url)\t\(.name)"'
CURSOR=$(echo "$PAGE" | jq -r '.next_cursor // empty')
[ -z "$CURSOR" ] && break
done
A cursor is opaque and doesn't expire; a malformed cursor or one from another owner is 400 invalid_request with field = cursor.
GET /codes/{id} — one code, the same object:
curl -sS "$API_BASE/codes/$CODE_ID" -H "Authorization: Bearer $API_KEY"
Someone else's code, an unknown or malformed id — 404 not_found.
Fields of a code worth knowing:
| Field | Meaning |
|---|---|
id |
number used in /codes/{id} |
short_url |
the link inside the QR image |
target_url |
where a url code redirects now; null for other types |
status |
active or disabled. Only the service disables a code |
disabled_reason |
null when active; unsafe_url (the link is on the unsafe list), reported (abuse reports), other. Treat an unknown value as other |
frozen_at |
set when the owner refunded the purchase: the code keeps working as printed but can't be changed any more |
batch |
{id, name} of the batch the code was created in, or null |
scans_total |
all scans ever; up to about 30 seconds behind |
updated_at |
last change of name or data |
A disabled code answers scanners with a "paused" page; its past stats stay readable.
6. Change a code
PATCH /codes/{id} — change name, data or both. Free. The printed QR doesn't change.
New link for a url code:
curl -sS -X PATCH "$API_BASE/codes/$CODE_ID" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"data":{"url":"https://joescafe.example/fall-menu"}}'
Answer 200 with the whole code after the change:
{"id": 1042, "type": "url", "name": "Café menu", "data": {"url": "https://joescafe.example/fall-menu"}, "target_url": "https://joescafe.example/fall-menu", "status": "active", "updated_at": "2026-10-12T09:30:00Z", "…": "…"}
New name only:
curl -sS -X PATCH "$API_BASE/codes/$CODE_ID" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"Fall menu"}'
Rules:
datais replaced as a whole, not merged: send every field the code should keep. This is also how you remove an optional field (for exampleutm). It's checked against the schema of the code's type, as on creation.typeandstatuscan't be changed: sending them is400 invalid_request. For another type, create a new code. An empty body{}is400.- Every link in the new
datais checked again (403 url_blockedif unsafe). If the check is unavailable, the change is saved anyway. - A code disabled for
unsafe_urlbecomesactiveagain after a change whose links all passed the check. Codes disabled forreportedorotherstay disabled; you can still change them. - A frozen code (
frozen_atset) —403 code_frozen. - The new link works at once in the same region and everywhere within about 60 seconds.
- Changing
datais limited to 10 a minute and, fordatawith links, 50 link checks in any 24 hours per owner (all keys and the app together). Re-pointing hundreds of codes takes several days: spread the changes and followRetry-After(see Limits). Changing onlyname, ordatawithout links (Wi-Fi, text, phone), doesn't use the daily cap.
Errors: 400, 401, 403 code_frozen / url_blocked, 404, 413, 429, 500.
7. Stats
GET /codes/{id}/stats?from=YYYY-MM-DD&to=YYYY-MM-DD — scans of one code by day, country and device type. from and to are UTC days, both included. Defaults: from — the day the code was created, to — today (UTC); without both you get all time.
Last 7 days (macOS date; on Linux use date -u -d '-6 days' +%F):
curl -sS "$API_BASE/codes/$CODE_ID/stats?from=$(date -u -v-6d +%F)" -H "Authorization: Bearer $API_KEY"
A fixed period:
curl -sS "$API_BASE/codes/$CODE_ID/stats?from=2026-10-05&to=2026-10-11" -H "Authorization: Bearer $API_KEY"
{
"total": 120,
"days": [
{"date": "2026-10-05", "count": 14},
{"date": "2026-10-07", "count": 31},
{"date": "2026-10-10", "count": 52},
{"date": "2026-10-11", "count": 23}
],
"countries": [
{"code": "US", "count": 71}, {"code": "CA", "count": 22}, {"code": "DE", "count": 9},
{"code": "GB", "count": 9}, {"code": "MX", "count": 6}, {"code": "XX", "count": 2}, {"code": "FR", "count": 1}
],
"devices": {"ios": 78, "android": 38, "other": 4}
}
dayslists only days with scans, oldest first; draw the missing days as zero.countries— ISO 3166 codes, most scans first;XXmeans unknown.devicesalways has all three keys.total= sum ofdays= sum ofcountries= sum ofdevices. No scans:total0, empty lists, zero devices.- Today's numbers are up to about 30 seconds behind.
- Only daily sums exist. There's no data about single scans: no IP addresses, no device identifiers, no time of day.
Errors: 400 invalid_request with field = from or to (not a real date in YYYY-MM-DD, or from later than to), 401, 404, 429, 500.
8. Many codes at once
POST /codes/batch — up to 500 codes in one request, all or nothing, one credit per code. Body: codes — an array of 1–500 items, each exactly the body of POST /codes; name — optional batch name (1–100 characters). Idempotency-Key is required, as for one code.
curl -sS -X POST "$API_BASE/codes/batch" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"name": "listings-oct",
"codes": [
{"type": "url", "name": "12 Oak Street", "data": {"url": "https://homes.example/12-oak-street"}},
{"type": "url", "name": "7 Elm Avenue", "data": {"url": "https://homes.example/7-elm-avenue"}},
{"type": "url", "name": "40 Pine Road", "data": {"url": "https://homes.example/40-pine-road"}}
]
}'
Answer 201: {"batch_id": 31, "name": "listings-oct", "created_at": "…", "codes": [ … ]}. codes[i] is the code for row i of your request, each with batch = {"id": 31, "name": "listings-oct"}.
If any row is bad, nothing is created and the answer is 422 batch_invalid with every bad row (its first problem), by index — the 0-based position in codes; field points inside that row:
{
"error": {
"code": "batch_invalid",
"message": "2 invalid rows",
"rows": [
{"index": 3, "code": "invalid_url", "message": "Only http and https links up to 2048 characters are allowed", "field": "/data/url"},
{"index": 41, "code": "invalid_data", "message": "Missing required property ssid", "field": "/data/ssid"}
]
}
}
Fix the listed rows and send the whole batch again with a new Idempotency-Key. Links are checked against the unsafe list only after every row is valid, so a fixed batch can still come back with url_blocked rows. Links already checked in the refused batch are not checked again and don't count against the limit of refused checks, so the fixed batch passes even after a large refused one; once it is created, they are paid. Only the unsafe links and rows you remove from the batch keep counting for 24 hours.
Other errors: more than 500 rows — 413 batch_too_large; body over 8 MiB — 413 payload_too_large; fewer credits than rows — 402 no_credits; 5 batches an hour per owner — 429; 50 or more refused link checks in the last 24 hours, not counting the links of this batch — 429 (every unique link of a refused batch counts until a code with it is created, see Limits). Codes of a batch don't count against the hourly limit of single codes.
9. Errors
Every error has the same body:
{"error": {"code": "invalid_data", "message": "…", "field": "/data/password"}}
code— what to branch on, always with the same HTTP status (table below). Treat an unknowncodeby its HTTP status.message— for your logs; the wording may change.field— where the problem is, when there is one: a JSON Pointer into your body (/name,/data/url,/data/phones/0), or a parameter or header name (cursor,from,Idempotency-Key).rows— only inbatch_invalid.
| HTTP | code |
Meaning | What to do |
|---|---|---|---|
| 400 | invalid_request |
body is not JSON, a field is missing, has the wrong type or is unknown; bad query parameter or Idempotency-Key |
fix the request at field |
| 400 | invalid_data |
data doesn't match the schema of its type |
fix data at field |
| 400 | invalid_url |
a link is not http(s), doesn't parse or is too long |
fix the link at field |
| 401 | unauthorized |
no key, malformed, unknown or revoked key | check the header; create a new key in the app |
| 402 | no_credits |
not enough credits | buy codes in the app, then retry |
| 403 | url_blocked |
a link is on Google's unsafe list | use another link |
| 403 | code_frozen |
the code is frozen after a refund | create a new code |
| 403 | forbidden_for_api_key |
the operation is app-only (purchases, API keys) | do it in the app |
| 404 | not_found |
no such code, someone else's code, or no such route | check the id and the path |
| 413 | payload_too_large |
body over 64 KiB (8 MiB for batches) | send less |
| 413 | batch_too_large |
more than 500 rows | split the batch |
| 422 | batch_invalid |
some batch rows are bad; see rows |
fix those rows, resend with a new key |
| 429 | rate_limited |
a limit is reached | wait Retry-After seconds, then retry |
| 500 | internal_error |
server problem | retry later with the same Idempotency-Key |
Examples:
# 401 — no key
curl -sS -i "$API_BASE/credits"
# 400 — Idempotency-Key is missing
curl -sS -X POST "$API_BASE/codes" \
-H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
-d '{"type":"text","name":"Note","data":{"text":"Hi"}}'
# 400 — invalid_data: WPA without a password
curl -sS -X POST "$API_BASE/codes" \
-H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"type":"wifi","name":"Guest","data":{"ssid":"Guest","security":"WPA","hidden":false}}'
# 400 — invalid_url
curl -sS -X POST "$API_BASE/codes" \
-H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"type":"url","name":"Menu","data":{"url":"ftp://joescafe.example/menu"}}'
# 400 — type can't change
curl -sS -X PATCH "$API_BASE/codes/$CODE_ID" \
-H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
-d '{"type":"text"}'
# 404 — not your code (or no such code)
curl -sS "$API_BASE/codes/999999999/stats" -H "Authorization: Bearer $API_KEY"
# 403 — API keys can't manage keys
curl -sS "$API_BASE/api-keys" -H "Authorization: Bearer $API_KEY"
Answers, in the same order (message may read differently — don't parse it):
{"error":{"code":"unauthorized","message":"Missing or invalid bearer token"}}
{"error":{"code":"invalid_request","message":"Missing required header","field":"Idempotency-Key"}}
{"error":{"code":"invalid_data","message":"Missing required field","field":"/data/password"}}
{"error":{"code":"invalid_url","message":"Only http and https links up to 2048 characters are allowed","field":"/data/url"}}
{"error":{"code":"invalid_request","message":"Unknown field","field":"/type"}}
{"error":{"code":"not_found","message":"Not found"}}
{"error":{"code":"forbidden_for_api_key","message":"API keys can't make purchases, manage API keys or use Sign in with Apple"}}
The 401 also carries the header WWW-Authenticate: Bearer.
10. Limits and Retry-After
Over a limit the answer is 429 rate_limited with the header Retry-After: <seconds>. Nothing was done: wait that long and send the same request again. For example, the 11th data change within a minute:
HTTP/1.1 429 Too Many Requests
Retry-After: 60
Content-Type: application/json
{"error":{"code":"rate_limited","message":"Too many data changes"}}
| Limit | Value | Counted for | Retry-After |
|---|---|---|---|
| Requests | 600 a minute | each API key | up to 60 |
Single new codes (POST /codes) with API keys |
100 an hour | all API keys of the owner together | until the oldest of those codes is an hour old |
| Single new codes in the app | 10 an hour | the owner key (the app), separate from the 100 above | — |
Batches (POST /codes/batch) |
5 an hour, up to 500 codes each | the owner: API keys and the app together | until the oldest batch is an hour old |
Data changes (PATCH with data) |
10 a minute | the owner: API keys and the app together | up to 60 |
Link checks on change (PATCH with data that has links) |
50 in any 24 hours | the owner: API keys and the app together | until the oldest counted change is 24 hours old |
Refused link checks on create (POST /codes, POST /codes/batch with links that created nothing: url_blocked; links of the request itself don't count) |
50 in any 24 hours | the owner: API keys and the app together | until the 50th newest of them is 24 hours old; 1 while your other create requests are still running |
Same Idempotency-Key still running |
— | the owner | 1 |
- Your integration and the app don't take single-code quota from each other: the app has its own 10 an hour, your keys share 100 an hour.
- For more than 100 codes an hour use batches: 5 × 500 = 2 500 codes an hour.
- Changing links in bulk takes days. 50 link changes in 24 hours per owner (the app counts too). To re-point 300
urlcodes, send changes until you get429, then waitRetry-After(up to 24 hours) and continue — the whole job takes about 6 days. Plan bulk changes ahead. - A repeat that gets a stored
Idempotency-Keyanswer counts only toward the per-minute request limit. - Per-minute limits are approximate and counted per Cloudflare region; hourly and daily limits are exact.
Up to 10 active API keys per owner.
11. Good practice
Retries and Idempotency-Key
Creating codes spends money, so POST /codes and POST /codes/batch require Idempotency-Key:
- Make a new key (a UUID) for each code or batch you mean to create, store it with your record, and send the same key on every retry of that request. A repeat within 24 hours returns the first
201— the same code, no second credit spent — even if it comes after a timeout, a500or a dropped connection. - Only successful answers are stored. After an error (
400,402,429,500…) nothing was created: retry with the same key; after fixing the body, a new key is cleaner. 429withRetry-After: 1on create means a request with this key is still running: wait a second and repeat.- The key is per owner and operation: the same key in
POST /codesandPOST /codes/batchmeans two different requests. PATCHhas noIdempotency-Key: it spends nothing, and repeating it leaves the code in the same state (it counts toward the data change limits again).
Retry policy
| Answer | Retry? |
|---|---|
2xx |
done |
429 |
yes, after Retry-After seconds |
500, network error, timeout |
yes, with backoff (1 s, 2 s, 4 s … up to a minute), same Idempotency-Key |
400, 401, 402, 403, 404, 413, 422 |
no — fix the cause first |
Keys
- One key per system (website, CRM, Zapier) — so you can revoke one without touching the others.
- A key leaked? Revoke it in the app right away and create a new one. Codes it created keep working.
- The API never returns the key again and never logs it.
Text
Send JSON as UTF-8. Python's json.dumps escapes non-ASCII by default; pass ensure_ascii=False for large batches, otherwise a batch of long non-Latin contacts can exceed 8 MiB.
What the API doesn't do
- Buy credits — only in the app.
- Delete codes — codes are permanent; the service may disable a code with an unsafe link or abuse reports.
- Change a code's
typeorstatus. - Give data about the people who scan: only daily sums by country and device type.
Questions: support@4qr.app.