Receiving the files
Documents @snap4id-sdk/app-embed 1.0.0 · @snap4id-sdk/embed-protocol 1.0.0 · @snap4id-sdk/partner-api 1.0.0 · protocol 1.0
After the user paid, Snap4ID delivers every file of the order to your app, whatever the done screen shows. The files are not kept for you: the links in a delivery expire with the job after 30 days, so your app (or your backend) downloads and stores them.
Delivery paths
Section titled “Delivery paths”flowchart LR
SV[Snap4ID]
subgraph phone[User's phone]
P[Snap4ID page]
H[Your app]
F[(Your app storage)]
P -->|"job.completed (bridge)"| H
H -->|download each url| F
end
B[Your backend]
ST[(Your server storage)]
SV -->|paid, links signed| P
SV -.->|"job.paid webhook (optional)"| B
B -->|"Partner API GET job"| SV
B -->|download each url| ST
- In the app (always): the page sends
job.completedover the bridge; your app downloads each file. - On your backend (optional): a signed
job.paidwebhook tells you a job was paid; your backend reads the job’s files with the Partner APIgetJoband downloads them. Use it when files must reach your servers too, or to recover a delivery the app never completed.
What the app gets: job.completed
Section titled “What the app gets: job.completed”Sent once the job is paid and every file has a link, never with a partial set.
| Field | Type | Meaning |
|---|---|---|
jobId |
string | the paid job |
orderCode |
string | six characters, shown to the user and quoted to support |
artifacts[] |
array | every deliverable file of the order |
artifacts[].code |
string | the file’s artifact code (stable per document; use it as a key) |
artifacts[].title |
string | a title in the session language, for your UI |
artifacts[].mimeType |
string | image/jpeg, image/png or application/pdf |
artifacts[].filename |
string | a safe file name to save under (letters, digits, _ . -) |
artifacts[].url |
string | time-limited signed download URL, usually on storage.googleapis.com; opaque (see below) |
artifacts[].expiresAt |
date-time | when the link stops working: the job’s expiry, 30 days after it was created |
{ "jobId": "eu-6f1c2b9e-3d4a-4b8f-9c2e-1a7d5e3f0b42", "orderCode": "7K3M9Q", "artifacts": [ { "code": "photo-main", "title": "Zdjęcie do dowodu", "mimeType": "image/jpeg", "filename": "snap4id-photo.jpg", "url": "https://storage.googleapis.com/example-bucket/…/photo.jpg?GoogleAccessId=…&Expires=…&Signature=…", "expiresAt": "2026-12-24T12:00:00.000Z" } ]}About url: it is a time-limited signed download URL, today a Google Cloud Storage link on
storage.googleapis.com (its query string carries the signature). Treat it as opaque: don’t parse, rewrite or
shorten it, and don’t assume a host, which may change. Plain HTTPS works on iOS (App Transport Security) and Android
without extra configuration; if your app, network security configuration, proxy or backend firewall allow-lists
hosts, allow storage.googleapis.com. The file is deleted at expiresAt (the job’s expiry), whatever the link says.
Full schema: job.completed.
Which files
Section titled “Which files”The files are the deliverables of the document the user ordered, as defined in Snap4ID’s document metadata. For an ID or passport photo they are typically:
| File | Type |
|---|---|
| the main photo | JPG |
| a print sheet with several copies | JPG |
| the same print sheet | |
| the photo with a transparent background | PNG |
Previews and thumbnails are never delivered. The set and the codes can differ per document and may grow, so don’t
hard-code a fixed list: iterate artifacts, key by code, and use mimeType and title for display.
Guarantees
Section titled “Guarantees”- At least once, not exactly once.
job.completedis sent on every page load of a paid job, and again when the job is reopened (/embed/{partnerId}/job/{jobId}). Store the delivery idempotently byjobId(andcode). - Survives a kill. If the app dies before the files are stored, the next start delivers them again: the React
Native component reopens paid, undelivered jobs in a hidden WebView (
client.start()+<Snap4IdResume>); a native host does the same by reopening the job’s URL. See delivery and recovery. - Links live 30 days (
expiresAt), then the job and its files are deleted. Copy the files, don’t keep links.
React Native: the component’s download helper
Section titled “React Native: the component’s download helper”The component never downloads by itself. Call the helper from onCompleted: it copies every file into
snap4id/<namespace>/jobs/<jobId>/ in the app’s documents directory, records them, skips files already stored, and
rejects until every file is stored, so the component calls onCompleted again (an expired link also makes it
reopen the job for fresh data).
export const snap4id = createSnap4IdClient({ partnerId: 'your-partner-id', purchases: 'built-in', onCompleted: (completion) => snap4id.downloadArtifacts(completion), // idempotent by jobId});The stored files are in client.downloads: list() and forJob(jobId) return a promise of the stored files;
subscribe(listener) calls listener(files) with the full, updated list after every change and returns an
unsubscribe function. Each file is { jobId, code, title, mimeType, filename, localUri, bytes }.
// A list that follows new deliveries.const [files, setFiles] = useState<DownloadedFile[]>([]);useEffect(() => { void snap4id.downloads.list().then(setFiles); return snap4id.downloads.subscribe(setFiles);}, []);// Show a job's main photo, and save or share any file.const files = await snap4id.downloads.forJob(jobId);const photo = files.find((f) => f.mimeType === 'image/jpeg');
<Image source={{ uri: photo.localUri }} style={{ width: 120, height: 150 }} />;await snap4id.files.save(jobId, photo.code); // to the photo libraryawait snap4id.files.share(jobId, photo.code); // the system share sheetclient.files uses the stored copy, or a temporary copy of the job’s last link when none was stored. Failures
throw; inside the flow the component reports them as save_failed / share_failed. A complete “My photos” screen
is in the SDK repository: examples/partner-app/src/photos.ts.
Any native app: download from the URLs
Section titled “Any native app: download from the URLs”On job.completed, download each url to your app’s storage under its filename, record it, then mark the job
delivered. Do it again for a job whose files are not all stored yet.
// iOSfunc store(_ completion: JobCompleted) async throws { let dir = URL.documentsDirectory.appending(path: "snap4id/\(completion.jobId)") try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) for artifact in completion.artifacts { let target = dir.appending(path: artifact.filename) if FileManager.default.fileExists(atPath: target.path) { continue } // idempotent let (temp, response) = try await URLSession.shared.download(from: URL(string: artifact.url)!) guard (response as? HTTPURLResponse)?.statusCode == 200 else { throw DeliveryError.link } try FileManager.default.moveItem(at: temp, to: target) } try markDelivered(completion.jobId)}// Android (OkHttp)fun store(completion: JobCompleted) { val dir = File(context.filesDir, "snap4id/${completion.jobId}").apply { mkdirs() } for (artifact in completion.artifacts) { val target = File(dir, artifact.filename) if (target.exists()) continue // idempotent http.newCall(Request.Builder().url(artifact.url).build()).execute().use { response -> check(response.isSuccessful) { "download failed: ${response.code}" } response.body!!.byteStream().use { input -> target.outputStream().use { input.copyTo(it) } } } } markDelivered(completion.jobId)}Show images with your image view; save to the photo library (iOS PHPhotoLibrary, Android MediaStore) or share
(UIActivityViewController, Intent.ACTION_SEND with a FileProvider URI). When the page sends artifact.save /
artifact.share, do the same for that code (done screen).
On your backend: Partner API and webhook
Section titled “On your backend: Partner API and webhook”job.paidwebhook:{ event_id, type, job_id, payment_ref, order_code, paid_at }, with no files. Verify it, then read the job (webhooks).GET /api/v1/partner/jobs/{jobId}(snap4id.getJob(jobId)): oncepaidistrue,artifactslists each file as{ code, title, mime_type, filename, url, expires_at }, in the same order as in the app. The links are the job’s own signed download URLs (the same on every call, the same kind as in the app), valid untilexpires_at.
const job = await snap4id.getJob(jobId);if (job.paid) for (const file of job.artifacts ?? []) await copyToStorage(file.url, file.filename);The backend file names include the order code, for example snap4id-7K3M9Q-<code>.jpg, so they don’t collide
across jobs in one bucket.
When something goes wrong
Section titled “When something goes wrong”| Situation | What to do |
|---|---|
| a download fails (network) | keep what is stored and retry the rest; the component’s helper does this and rejects, so onCompleted runs again |
a link answers 403 / 410 before expiresAt |
reopen the job (/embed/{partnerId}/job/{jobId}) for a fresh job.completed; the component does this itself |
| files not ready 30 s after payment | the page sends artifacts_unavailable (not fatal) and keeps waiting; nothing to do |
| the app was killed before storing | the next start delivers again (recovery) |
| more than 30 days passed | the job and its files are gone; nothing can be recovered, so store files when they arrive |
