Quickstart
This quickstart walks you through uploading your first image with the Nooknear API, waiting for the WebP variants to be generated, and showing the result on a page with <img srcset>. There are five steps, with examples for curl, Node.js (built-in fetch, Node 18+) and the browser.
1. Get your API key
Today, API keys are created by our team when you sign up and sent to you. You get two values:
tenantId: the UUID of your account (tenant). You need it as a path parameter for the usage and GDPR endpoints.- API key: starts with
np_. Send it in theX-API-Keyheader on every request.
A web dashboard where you can create and manage keys yourself is coming soon. Don’t hard-code the key; keep it in an environment variable:
export NOOKNEAR_API_KEY="np_..."
See Authentication for details.
2. Request an upload URL
You attach each image to a record in your system using resourceType (for example product or event) and resourceId (your own ID). You also send the file name, MIME type and size in bytes.
curl -X POST https://api.nooknear.com/v1/media/upload-request \
-H "X-API-Key: $NOOKNEAR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: product-42-cover-1" \
-d '{
"resourceType": "product",
"resourceId": "42",
"filename": "cover.jpg",
"mimeType": "image/jpeg",
"sizeBytes": 534120
}'
Response, 201 Created:
{
"uploadUrl": "https://...r2.cloudflarestorage.com/...&X-Amz-Signature=...",
"assetId": "3f6c2a8e-1b4d-4c1e-9a77-5e2f0d8b9c10",
"expiresAt": "2026-12-06T12:15:00.000Z"
}
uploadUrl is valid for 15 minutes. See Uploads for every field and limit.
3. PUT the file
The file never passes through the API server; it goes straight to storage. The Content-Type header must be exactly the mimeType you sent in step 2, otherwise the signature doesn’t match and storage rejects the request.
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: image/jpeg" \
--data-binary @cover.jpg
4. Poll until ready
Once the file arrives, the queue processes it. status moves from pending to processing, then to ready (or failed if something goes wrong).
curl https://api.nooknear.com/v1/media/3f6c2a8e-1b4d-4c1e-9a77-5e2f0d8b9c10 \
-H "X-API-Key: $NOOKNEAR_API_KEY"
A ready response (trimmed):
{
"assetId": "3f6c2a8e-1b4d-4c1e-9a77-5e2f0d8b9c10",
"status": "ready",
"resourceType": "product",
"resourceId": "42",
"variants": {
"small": { "url": "https://cdn.nooknear.com/<tenantId>/product/42/3f6c.../small.webp?token=...", "width": 400, "height": 300, "sizeBytes": 18234, "mimeType": "image/webp" },
"medium": { "url": "https://cdn.nooknear.com/.../medium.webp?token=...", "width": 800, "height": 600, "sizeBytes": 47120, "mimeType": "image/webp" },
"large": { "url": "https://cdn.nooknear.com/.../large.webp?token=...", "width": 1200, "height": 900, "sizeBytes": 88410, "mimeType": "image/webp" },
"thumb": { "url": "https://cdn.nooknear.com/.../thumb.webp?token=...", "width": 150, "height": 150, "sizeBytes": 6012, "mimeType": "image/webp" }
},
"createdAt": "2026-12-06T12:00:00.000Z"
}
Customer webhooks are coming soon; for now, polling every few seconds is the way to go. Every poll counts toward your rate limit, so back off as you wait.
5. Use the variants in srcset
Variant URLs don’t need an API key, so you can hand them straight to the browser. Take the width values from each variant’s width field:
<img
src="https://cdn.nooknear.com/.../medium.webp?token=..."
srcset="
https://cdn.nooknear.com/.../small.webp?token=... 400w,
https://cdn.nooknear.com/.../medium.webp?token=... 800w,
https://cdn.nooknear.com/.../large.webp?token=... 1200w"
sizes="(max-width: 600px) 100vw, 600px"
width="1200" height="900"
alt="Product cover photo"
loading="lazy">
More on srcset and sizes in Variants and CDN.
End-to-end Node.js example
This script uploads a file, waits until it’s ready and prints the variant URLs.
import { readFile, stat } from 'node:fs/promises';
const API = 'https://api.nooknear.com';
const KEY = process.env.NOOKNEAR_API_KEY;
async function api(path, init = {}) {
const res = await fetch(API + path, {
...init,
headers: { 'X-API-Key': KEY, 'Content-Type': 'application/json', ...init.headers }
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return res.json();
}
async function uploadImage(filePath, mimeType, resourceType, resourceId) {
const { size } = await stat(filePath);
// 1) Request an upload URL
const { uploadUrl, assetId } = await api('/v1/media/upload-request', {
method: 'POST',
headers: { 'Idempotency-Key': `${resourceType}-${resourceId}-${size}` },
body: JSON.stringify({ resourceType, resourceId, filename: filePath.split('/').pop(), mimeType, sizeBytes: size })
});
// 2) Send the file straight to storage
const put = await fetch(uploadUrl, {
method: 'PUT',
headers: { 'Content-Type': mimeType },
body: await readFile(filePath)
});
if (!put.ok) throw new Error(`PUT failed: ${put.status}`);
// 3) Wait until ready, backing off between polls
for (let delay = 1000; delay <= 16000; delay *= 2) {
await new Promise((r) => setTimeout(r, delay));
const asset = await api(`/v1/media/${assetId}`);
if (asset.status === 'ready') return asset;
if (asset.status === 'failed') throw new Error('Processing failed');
}
throw new Error('Timed out waiting for the asset');
}
const asset = await uploadImage('./cover.jpg', 'image/jpeg', 'product', '42');
console.log(asset.variants.large.url);
Uploading from the browser
Your API key must never reach the browser. The pattern is: the browser sends the file details to your own server, your server calls upload-request and returns only uploadUrl and assetId, and the browser then PUTs the file directly to uploadUrl.
// Browser side. /api/upload-url is an endpoint on your own server.
const input = document.querySelector('input[type=file]');
input.addEventListener('change', async () => {
const file = input.files[0];
const res = await fetch('/api/upload-url', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: file.name, mimeType: file.type, sizeBytes: file.size })
});
const { uploadUrl, assetId } = await res.json();
await fetch(uploadUrl, {
method: 'PUT',
headers: { 'Content-Type': file.type },
body: file
});
// Save assetId on your server and poll the status from there.
console.log('Uploaded:', assetId);
});
The server-side /api/upload-url handler is the same upload-request call as in the Node.js example; validate the user’s file type and size there as well. A drop-in upload component and a TypeScript SDK are coming soon.
Next steps
- Uploads:
outputFormats, tags and metadata. - Listing and filtering: Fetch every image for a record in one request.
- Errors and limits: Retries and rate limits.