Skip to main content

Cloud REST with JavaScript

Use standard fetch against the experimental Cloud API; VisionScan does not publish a native npm scanner package.

SDK 0.1.0-RC5 · Experimental

Status: Experimental

These examples call the same authenticated upload, job, and status HTTP API. They are REST clients, not native VisionScan scanner SDKs. VisionScan does not publish Cloud client packages to PyPI, npm, NuGet, Maven Central, or RubyGems in RC2.

The service contract is:

  1. POST /v1/uploads with an idempotency key, base64 image, and allowlisted content type.
  2. POST /v1/jobs with an idempotency key, one or more returned upload IDs, and a scan profile.
  3. GET /v1/jobs/{jobId} until completed or failed .

Tenant and site scope come from the verified bearer token. Never send or accept a tenant override in the JSON body.

HTTP contract reference

Every language on this page calls the same three contracts:

Contract Required request Success result Failure behavior
POST /v1/uploads Bearer token, tenant-scoped idempotency key, bounded base64 image, allowlisted content type matching magic bytes uploadId and non-sensitive upload metadata 401/403 identity or entitlement denial; 409 changed payload under a reused key; 4xx invalid bytes/type/size; 429 quota
POST /v1/jobs Bearer token, idempotency key, same-tenant uploadIds , allowlisted profile jobId , queued state, correlation metadata Cross-tenant/unknown upload denial, idempotency conflict, invalid profile, or quota failure
GET /v1/jobs/{jobId} Bearer token in the owning tenant/site scope Pending, completed, or failed status with receipt/error metadata Cross-tenant data is never exposed; ENGINE_ADAPTER_UNAVAILABLE is failed, not an empty successful scan

Client code must reject non-2xx responses and unknown response shapes. A retry of an identical request retains its idempotency key; changed content receives a new key. The machine-readable request/status schemas and contracts/sdk-public-contracts.json are the frozen contract sources.

Common environment

Set VISIONSCAN_CLOUD_URL and VISIONSCAN_ACCESS_TOKEN in the process secret store. Loopback development may use the explicitly documented --dev token format. Production requires an RS256 token with bounded timestamps and the cloud-scan entitlement.

Use image/png , image/jpeg , or image/webp . Enforce local image-size limits before base64 encoding. Every retry of an identical request should retain its original idempotency key; changed content needs a new key.

JavaScript and TypeScript

Node.js 20 includes fetch . Keep the token on a trusted server, not in public browser code.

import { readFile } from "node:fs/promises";
import { randomUUID } from "node:crypto";

const base = process.env.VISIONSCAN_CLOUD_URL.replace(/\/$/, "");
const headers = {
  Authorization: `Bearer ${process.env.VISIONSCAN_ACCESS_TOKEN}`,
  "Content-Type": "application/json",
};

async function request(path, init = {}) {
  const response = await fetch(`${base}${path}`, { ...init, headers });
  if (!response.ok) throw new Error(`VisionScan HTTP ${response.status}`);
  return response.json();
}

const image = await readFile("label.png");
const upload = await request("/v1/uploads", {
  method: "POST",
  body: JSON.stringify({
    idempotencyKey: randomUUID(),
    contentBase64: image.toString("base64"),
    contentType: "image/png",
  }),
});
const job = await request("/v1/jobs", {
  method: "POST",
  body: JSON.stringify({
    idempotencyKey: randomUUID(),
    uploadIds: [upload.uploadId],
    profile: "still-image-dense",
  }),
});
console.log(await request(`/v1/jobs/${job.jobId}`));

Add an AbortController timeout and bounded retry policy in production.

Error handling

Condition Client action
401 or 403 Refresh credentials and confirm the cloud-scan entitlement. Do not retry indefinitely.
409 idempotency conflict Reuse the key only with the original payload or generate a new key for changed content.
429 or quota error Apply bounded backoff and respect the tenant quota.
ENGINE_ADAPTER_UNAVAILABLE Treat the job as failed. The experimental host has no production engine adapter.
Unknown or invalid response shape Fail closed and preserve non-sensitive correlation metadata for support.

The local development service can prove authentication, tenant isolation, persistence, idempotency, quotas, and job lifecycle. Its empty development receipt is not evidence of a barcode decode. Production certification requires an approved Linux engine adapter and deployment artifact.

Support matrix

Full API contract reference

Public contract reference

These are the callable methods and HTTP operations used by this guide. Inputs, results, lifecycle rules, and denial behavior are part of the versioned customer contract.

Cloud upload contract

Upload bytes are authenticated, bounded, MIME-checked, idempotent, and tenant-scoped.

POST /v1/uploads

http

Persist one validated image and return a tenant-scoped upload identifier.

Inputs for POST /v1/uploads
InputTypeRequiredMeaning
AuthorizationBearer tokenYesProduction RS256 token with bounded time claims and cloud-scan entitlement.
idempotencyKeyUUID/stringYesTenant-scoped key reused only for an identical retry.
contentBase64base64 stringYesLocally bounded PNG, JPEG, or WebP bytes.
contentTypestringYesimage/png, image/jpeg, or image/webp matching the file magic bytes.
Result
2xx JSON containing uploadId and non-sensitive upload metadata.
Lifecycle
Upload before creating a job; retain the idempotency key for retries of the same bytes.
Trust boundary
Tenant and site come only from the verified token; request bodies cannot override tenant scope.
Failure behavior
  • 401/403 for invalid or unentitled identity.
  • 409 for a reused key with different content.
  • 4xx for invalid MIME, magic bytes, base64, or size; 429 for quota limits.

Cloud job creation contract

A job references same-tenant uploads and selects a bounded scan profile.

POST /v1/jobs

http

Create an asynchronous scan job from one or more previously accepted uploads.

Inputs for POST /v1/jobs
InputTypeRequiredMeaning
idempotencyKeyUUID/stringYesTenant-scoped key for identical job retries.
uploadIdsstring[]YesExisting upload IDs owned by the authenticated tenant and site.
profilestringYesAn allowlisted profile such as still-image-dense.
callbackHTTPS URLNoOptional policy-validated callback; production delivery requires the documented callback controls.
Result
2xx JSON containing jobId, queued status, and correlation metadata.
Lifecycle
Create after uploads succeed, then poll status until completed or failed.
Trust boundary
Callbacks reject non-HTTPS and non-global destinations, pin validated addresses, follow no redirects, and HMAC-sign payloads.
Failure behavior
  • Cross-tenant or unknown uploads are denied.
  • 409 reports idempotency conflict; 429 reports quota pressure; invalid profiles fail validation.

Cloud job status contract

Status retrieval distinguishes completed, failed, and unavailable-engine outcomes from an empty scan.

GET /v1/jobs/{jobId}

http

Read the authenticated tenant's job state, receipt, structured error, and callback delivery state.

Inputs for GET /v1/jobs/{jobId}
InputTypeRequiredMeaning
jobIdpath stringYesThe job identifier returned by POST /v1/jobs.
AuthorizationBearer tokenYesThe same tenant/site scope that owns the job.
Result
JSON status that becomes completed or failed; completed identity evidence remains GTIN-first and preserves review-required OCR provenance.
Lifecycle
Poll with bounded backoff and stop on a terminal state.
Trust boundary
Do not log bearer tokens, encoded images, or sensitive receipt payloads; retain only non-sensitive correlation metadata.
Failure behavior
  • Cross-tenant and unknown identifiers do not expose another tenant's data.
  • ENGINE_ADAPTER_UNAVAILABLE is a failed job, not a successful scan with zero observations.
  • Unknown response shapes fail closed.