Sirv REST API
Base URL: https://api.sirv.com
Official Sources First
Check current Sirv docs before changing endpoint fields, path escaping, metadata field names, or pagination behavior:
https://apidocs.sirv.com/
https://sirv.com/help/articles/search-files-with-the-api/
https://sirv.com/help/articles/add-meta-with-the-api/
https://sirv.com/help/articles/sirv-api/
Authentication
All requests require a Bearer token from /v2/token:
curl -X POST https://api.sirv.com/v2/token \
-H "Content-Type: application/json" \
-d '{"clientId": "YOUR_CLIENT_ID", "clientSecret": "YOUR_CLIENT_SECRET"}'
Response:
{"token": "eyJhbG...", "expiresIn": 1200, "scope": ["account:read", ...]}
Use token in subsequent requests:
curl https://api.sirv.com/v2/account \
-H "Authorization: Bearer eyJhbG..."
Tokens expire in 20 minutes. Request a new one before expiry.
Debugging Workflow
- Identify the exact endpoint and method in play.
- Reproduce or inspect the request body, query string, and response body.
- Compare the request shape against the official docs before patching code.
- Separate auth/token failures from Sirv payload/query failures.
- Preserve upstream status and useful Sirv error detail when surfacing failures.
- Add a focused regression test or fixture for the exact endpoint/query that failed.
Operational Rules
- URL-encode file and folder paths in query strings, especially
/ as %2F.
- Refresh tokens in long-running scripts; do not assume a token survives a bulk migration.
- Check
/v2/account/limits before bulk search/upload/delete jobs.
- Use
/v2/files/fetch to import remote originals directly into Sirv when source URLs are stable.
- Preserve catalog context with metadata after upload: title, description, tags, product fields, and approval state.
- Search returns up to 100 results per page. Use
from for normal pagination and scrolling search for more than 1000 results.
- Scrolling search is a point-in-time snapshot and is cached for about 20 minutes; download results promptly.
- Escape search special characters in paths:
{ } / \ ! space.
Quick Reference
File Operations
| Operation |
Method |
Endpoint |
Key Params |
| Upload |
POST |
/v2/files/upload |
?filename=/path/file.jpg + binary body |
| Download |
GET |
/v2/files/download |
?filename=/path/file.jpg |
| Delete |
POST |
/v2/files/delete |
?filename=/path/file.jpg |
| Copy |
POST |
/v2/files/copy |
?from=/a.jpg&to=/b.jpg |
| Rename/Move |
POST |
/v2/files/rename |
?from=/a.jpg&to=/b.jpg |
| Create folder |
POST |
/v2/files/mkdir |
?dirname=/new-folder |
| List directory |
GET |
/v2/files/readdir |
?dirname=/folder |
Metadata Operations
| Operation |
Method |
Endpoint |
| Get all meta |
GET |
/v2/files/meta?filename=/path |
| Set meta |
POST |
/v2/files/meta?filename=/path |
| Get/Set title |
GET/POST |
/v2/files/meta/title?filename=/path |
| Get/Set description |
GET/POST |
/v2/files/meta/description?filename=/path |
| Get/Add/Delete tags |
GET/POST/DELETE |
/v2/files/meta/tags?filename=/path |
| Get/Set product |
GET/POST |
/v2/files/meta/product?filename=/path |
Async Jobs (return job ID, poll for progress)
| Operation |
Start |
Poll |
| Spin to video |
POST /v2/files/spin2video |
Returns filename directly |
| Video to spin |
POST /v2/files/video2spin |
Returns filename directly |
| Create ZIP |
POST /v2/files/zip |
GET /v2/files/zip?id= |
| Batch delete |
POST /v2/files/batch/delete |
GET /v2/files/batch/delete?id= |
| 3D to GLB |
POST /v2/files/3d/model2GLB |
GET /v2/files/3d/model2GLB?id= |
When to Read Reference Files
- File operations (upload, download, copy, delete, directory listing): See files.md
- Metadata & search (meta fields, search query syntax, product data): See metadata.md
- Async jobs (video conversion, ZIP, batch ops): See jobs.md
- Account & stats (usage, billing, events, settings): See account.md
Common Patterns
Upload an image
const token = await getToken();
await fetch('https://api.sirv.com/v2/files/upload?filename=/images/photo.jpg', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'image/jpeg'
},
body: imageBuffer
});
Search for recent images
await fetch('https://api.sirv.com/v2/files/search', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: 'extension:.jpg AND mtime:[now-7d TO now]',
size: 50
})
});
Search a folder with escaped path
await fetch('https://api.sirv.com/v2/files/search', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: 'dirname.paths:\\/products AND extension:.jpg',
size: 100
})
});
Create ZIP archive (async)
// Start job
const { id } = await fetch('https://api.sirv.com/v2/files/zip', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
filenames: ['/images/photo1.jpg', '/images/photo2.jpg'],
zipFilename: '/downloads/photos.zip'
})
}).then(r => r.json());
// Poll until complete
let progress = 0;
while (progress < 100) {
const status = await fetch(`https://api.sirv.com/v2/files/zip?id=${id}`, {
headers: { 'Authorization': `Bearer ${token}` }
}).then(r => r.json());
progress = status.progress;
await new Promise(r => setTimeout(r, 1000));
}
Red Flags
- Changing Sirv request syntax from memory instead of current docs.
- Flattening Sirv 400/401/403/429/5xx responses into a generic local error.
- Treating search field names, path escaping, or page-size limits as generic Lucene behavior.
- Fixing token acquisition and request body shape in the same step without proving which boundary failed.
- Hiding the exact Sirv path, folder, tag, or payload involved in a failure.
Verification
- Reproduce the failing request with the exact folder, tag, file path, or payload.
- Confirm file paths are URL-encoded in query strings and escaped in search syntax where required.
- Confirm page size, pagination, or scrolling matches Sirv's documented behavior.
- Verify imported/uploaded files with
stat, meta, readdir, or search.
- Re-run the relevant integration/route test when this skill is used in a codebase.
1---2name: sirv-api3description: Sirv REST API integration for image and file management. Use when working with Sirv CDN, uploading/downloading files to Sirv, managing image metadata, searching files, creating 360 spins, converting videos, or any Sirv API operations. Covers authentication, file operations, metadata, search queries, async jobs, and account management.4---56# Sirv REST API78Base URL: `https://api.sirv.com`910## Official Sources First1112Check current Sirv docs before changing endpoint fields, path escaping, metadata field names, or pagination behavior:1314- `https://apidocs.sirv.com/`15- `https://sirv.com/help/articles/search-files-with-the-api/`16- `https://sirv.com/help/articles/add-meta-with-the-api/`17- `https://sirv.com/help/articles/sirv-api/`1819## Authentication2021All requests require a Bearer token from `/v2/token`:2223```bash24curl -X POST https://api.sirv.com/v2/token \25 -H "Content-Type: application/json" \26 -d '{"clientId": "YOUR_CLIENT_ID", "clientSecret": "YOUR_CLIENT_SECRET"}'27```2829Response:30```json31{"token": "eyJhbG...", "expiresIn": 1200, "scope": ["account:read", ...]}32```3334Use token in subsequent requests:35```bash36curl https://api.sirv.com/v2/account \37 -H "Authorization: Bearer eyJhbG..."38```3940Tokens expire in 20 minutes. Request a new one before expiry.4142## Debugging Workflow43441. Identify the exact endpoint and method in play.452. Reproduce or inspect the request body, query string, and response body.463. Compare the request shape against the official docs before patching code.474. Separate auth/token failures from Sirv payload/query failures.485. Preserve upstream status and useful Sirv error detail when surfacing failures.496. Add a focused regression test or fixture for the exact endpoint/query that failed.5051## Operational Rules5253- URL-encode file and folder paths in query strings, especially `/` as `%2F`.54- Refresh tokens in long-running scripts; do not assume a token survives a bulk migration.55- Check `/v2/account/limits` before bulk search/upload/delete jobs.56- Use `/v2/files/fetch` to import remote originals directly into Sirv when source URLs are stable.57- Preserve catalog context with metadata after upload: title, description, tags, product fields, and approval state.58- Search returns up to 100 results per page. Use `from` for normal pagination and scrolling search for more than 1000 results.59- Scrolling search is a point-in-time snapshot and is cached for about 20 minutes; download results promptly.60- Escape search special characters in paths: `{ } / \ ! space`.6162## Quick Reference6364### File Operations6566| Operation | Method | Endpoint | Key Params |67|-----------|--------|----------|------------|68| Upload | POST | `/v2/files/upload` | `?filename=/path/file.jpg` + binary body |69| Download | GET | `/v2/files/download` | `?filename=/path/file.jpg` |70| Delete | POST | `/v2/files/delete` | `?filename=/path/file.jpg` |71| Copy | POST | `/v2/files/copy` | `?from=/a.jpg&to=/b.jpg` |72| Rename/Move | POST | `/v2/files/rename` | `?from=/a.jpg&to=/b.jpg` |73| Create folder | POST | `/v2/files/mkdir` | `?dirname=/new-folder` |74| List directory | GET | `/v2/files/readdir` | `?dirname=/folder` |7576### Metadata Operations7778| Operation | Method | Endpoint |79|-----------|--------|----------|80| Get all meta | GET | `/v2/files/meta?filename=/path` |81| Set meta | POST | `/v2/files/meta?filename=/path` |82| Get/Set title | GET/POST | `/v2/files/meta/title?filename=/path` |83| Get/Set description | GET/POST | `/v2/files/meta/description?filename=/path` |84| Get/Add/Delete tags | GET/POST/DELETE | `/v2/files/meta/tags?filename=/path` |85| Get/Set product | GET/POST | `/v2/files/meta/product?filename=/path` |8687### Async Jobs (return job ID, poll for progress)8889| Operation | Start | Poll |90|-----------|-------|------|91| Spin to video | POST `/v2/files/spin2video` | Returns filename directly |92| Video to spin | POST `/v2/files/video2spin` | Returns filename directly |93| Create ZIP | POST `/v2/files/zip` | GET `/v2/files/zip?id=` |94| Batch delete | POST `/v2/files/batch/delete` | GET `/v2/files/batch/delete?id=` |95| 3D to GLB | POST `/v2/files/3d/model2GLB` | GET `/v2/files/3d/model2GLB?id=` |9697## When to Read Reference Files9899- **File operations** (upload, download, copy, delete, directory listing): See [files.md](references/files.md)100- **Metadata & search** (meta fields, search query syntax, product data): See [metadata.md](references/metadata.md)101- **Async jobs** (video conversion, ZIP, batch ops): See [jobs.md](references/jobs.md)102- **Account & stats** (usage, billing, events, settings): See [account.md](references/account.md)103104## Common Patterns105106### Upload an image107```javascript108const token = await getToken();109await fetch('https://api.sirv.com/v2/files/upload?filename=/images/photo.jpg', {110 method: 'POST',111 headers: {112 'Authorization': `Bearer ${token}`,113 'Content-Type': 'image/jpeg'114 },115 body: imageBuffer116});117```118119### Search for recent images120```javascript121await fetch('https://api.sirv.com/v2/files/search', {122 method: 'POST',123 headers: {124 'Authorization': `Bearer ${token}`,125 'Content-Type': 'application/json'126 },127 body: JSON.stringify({128 query: 'extension:.jpg AND mtime:[now-7d TO now]',129 size: 50130 })131});132```133134### Search a folder with escaped path135```javascript136await fetch('https://api.sirv.com/v2/files/search', {137 method: 'POST',138 headers: {139 'Authorization': `Bearer ${token}`,140 'Content-Type': 'application/json'141 },142 body: JSON.stringify({143 query: 'dirname.paths:\\/products AND extension:.jpg',144 size: 100145 })146});147```148149### Create ZIP archive (async)150```javascript151// Start job152const { id } = await fetch('https://api.sirv.com/v2/files/zip', {153 method: 'POST',154 headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },155 body: JSON.stringify({156 filenames: ['/images/photo1.jpg', '/images/photo2.jpg'],157 zipFilename: '/downloads/photos.zip'158 })159}).then(r => r.json());160161// Poll until complete162let progress = 0;163while (progress < 100) {164 const status = await fetch(`https://api.sirv.com/v2/files/zip?id=${id}`, {165 headers: { 'Authorization': `Bearer ${token}` }166 }).then(r => r.json());167 progress = status.progress;168 await new Promise(r => setTimeout(r, 1000));169}170```171172## Red Flags173174- Changing Sirv request syntax from memory instead of current docs.175- Flattening Sirv 400/401/403/429/5xx responses into a generic local error.176- Treating search field names, path escaping, or page-size limits as generic Lucene behavior.177- Fixing token acquisition and request body shape in the same step without proving which boundary failed.178- Hiding the exact Sirv path, folder, tag, or payload involved in a failure.179180## Verification181182- Reproduce the failing request with the exact folder, tag, file path, or payload.183- Confirm file paths are URL-encoded in query strings and escaped in search syntax where required.184- Confirm page size, pagination, or scrolling matches Sirv's documented behavior.185- Verify imported/uploaded files with `stat`, `meta`, `readdir`, or `search`.186- Re-run the relevant integration/route test when this skill is used in a codebase.