Typescript
This Typescript example shows how to use the Vaxtor Cloud ALPR API to request a plate analysis that includes Make, Model, and Color (MMC).
Code sample
typescript
import * as fs from "fs";
import fetch from "node-fetch";
const TOKEN_URL = "https://auth.vaxtor.cloud/connect/token";
const API_URL = "https://vaxtor.cloud/analysis/api/plate";
const CLIENT_ID = "PUT_YOU_CLIENT_ID_HERE";
const CLIENT_SECRET = "PUT_YOU_CLIENT_SECRET_HERE";
const SCOPE = "api";
// Get Token
async function getToken(): Promise<string | null> {
const response = await fetch(TOKEN_URL, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
scope: SCOPE,
}),
});
const data = await response.json();
return data.access_token || null;
}
// Analyze Image (raw binary upload)
async function sendImage(): Promise<any> {
const token = await getToken();
if (!token) {
throw new Error("Error getting token");
}
// Read file as binary stream
const fileStream = fs.createReadStream("image.jpg");
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/octet-stream",
// Optional region:
// "Vaxtor-Ocr-Region": "europe",
},
body: fileStream, // raw binary body
});
return response.json();
}
// Show Result
sendImage()
.then(result => console.log(result))
.catch(error => console.error("Error:", error));Code Overview
- Authentication
The script retrieves a bearer token via OAuth2 Client Credentials at https://auth.vaxtor.cloud/connect/token.
Export your client-id and client-secret before running the script:
bash
export VAXTOR_CLIENT_ID="your-client-id"
export VAXTOR_CLIENT_SECRET="your-client-secret"- API Request
Uses node-fetch to POST the raw image bytes as the request body (Content-Type: application/octet-stream) to https://vaxtor.cloud/analysis/api/plate together with the header Authorization: Bearer <token>.