Panoramica
Per accelerare l'integrazione backend in ambienti Node.js/TypeScript, Python, PHP e shell — insieme alle utility sviluppatore della Dashboard su /settings/workspace/integrations/link-generator, /settings/workspace/developer/embed-sdk, /settings/workspace/developer/sdks, /settings/workspace/developer/query-helper e /settings/workspace/developer/qr-generator — questa guida fornisce pattern di produzione per upsert idempotenti dei pass (POST /api/v1/passes/upsert-by-external-id), link di download parametrizzati (PARAMETERIZED_PASS_LINK / CREATE_PASS_URL), paginazione tramite cursore e verifica in tempo costante HMAC-SHA256 dei webhook.
Importante: Sincronizzi un record aziendale tramite upsert su
(templateId, externalId). Il pass restituito è indata.passe il risultato indata.action(CREATEDoUPDATED). PerPOST /api/v1/passes, invii un headerIdempotency-Keyaffinché i tentativi successivi riutilizzino la stessa richiesta di creazione. L’endpoint di upsert non elabora questo header.
Flusso di upsert idempotente e paginazione a cursore
Pattern di codice multilingua pronti per la produzione
1. Node.js / TypeScript: helper idempotente di upsert pass
interface IUpsertPassPayload {
templateId: string;
externalId: string;
attributes: Record<string, string | number | boolean>;
expirationDate?: string;
}
export async function upsertWalletPass(payload: IUpsertPassPayload) {
const response = await fetch('https://api.passinstance.com/api/v1/passes/upsert-by-external-id', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.PASSINSTANCE_API_KEY ?? '',
},
body: JSON.stringify(payload),
});
const body = await response.json();
if (!response.ok || !body.success) {
throw new Error(`Passinstance API error [${body.errorCode ?? response.status}]: ${body.message}`);
}
return body.data.pass as { id: string; serialNumber: string; externalId?: string; passAccessUrl: string };
}
2. Python: upsert idempotente e verificatore HMAC per webhook
import hmac
import hashlib
import os
import requests
API_BASE_URL = "https://api.passinstance.com/api/v1"
API_KEY = os.environ["PASSINSTANCE_API_KEY"]
def upsert_pass_by_external_id(template_id: str, external_id: str, attributes: dict) -> dict:
response = requests.post(
f"{API_BASE_URL}/passes/upsert-by-external-id",
headers={
"x-api-key": API_KEY,
"Content-Type": "application/json",
},
json={
"templateId": template_id,
"externalId": external_id,
"attributes": attributes,
},
timeout=10,
)
response.raise_for_status()
return response.json()["data"]["pass"]
def verify_webhook_signature(raw_body: bytes, signature_header: str, secret: str) -> bool:
if not signature_header or not signature_header.startswith("sha256="):
return False
digest = hmac.new(secret.encode("utf-8"), raw_body, hashlib.sha256).hexdigest()
expected = f"sha256={digest}"
return hmac.compare_digest(signature_header, expected)
3. PHP: emissione/aggiornamento pass e verifica webhook
<?php
function upsertPassinstancePass(string $templateId, string $externalId, array $attributes): array {
$payload = json_encode([
'templateId' => $templateId,
'externalId' => $externalId,
'attributes' => $attributes,
], JSON_THROW_ON_ERROR);
$ch = curl_init('https://api.passinstance.com/api/v1/passes/upsert-by-external-id');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'x-api-key: ' . getenv('PASSINSTANCE_API_KEY'),
],
]);
$raw = curl_exec($ch);
curl_close($ch);
return json_decode($raw, true, 512, JSON_THROW_ON_ERROR)['data']['pass'];
}
function verifyPassinstanceWebhook(string $rawBody, string $signatureHeader, string $secret): bool {
$expected = 'sha256=' . hash_hmac('sha256', $rawBody, $secret);
return hash_equals($expected, $signatureHeader);
}
4. cURL: riferimento rapido da CLI
curl -X POST "https://api.passinstance.com/api/v1/passes/upsert-by-external-id" \
-H "Content-Type: application/json" \
-H "x-api-key: pi_live_89a1f4c2e90b41d7a6c3e2f10984b2c1" \
-d '{
"templateId": "6f2c5130-2f2a-4f40-8c68-f7192c5b4f43",
"externalId": "cust_9012",
"attributes": {
"memberName": "Clara Oswald",
"points": 1250,
"tier": "GOLD"
}
}'
Paginazione degli snapshot dello scanner offline
GET /api/v1/scans/offline-dataset richiede x-scanner-key e restituisce lo snapshot in una risposta con success, data e metadata. Mantenga lo stesso snapshotAt in tutte le pagine.
| Parametro / Campo di risposta | Tipo | Descrizione |
|---|---|---|
limit | number | Pass per pagina (valore predefinito 500, massimo 1000). |
cursor | string | Usi data.nextCursor della risposta precedente; lo ometta nella prima richiesta. |
snapshotAt | string (ISO 8601) | Riutilizzi data.snapshotAt della prima risposta come limite superiore dello snapshot nelle pagine successive. |
data.passes | Array | Snapshot dei pass limitati alla configurazione dello scanner. |
data.hasMore | boolean | Continui a recuperare pagine finché questo valore è true. |
data.nextCursor | string | Da usare come cursor quando data.hasMore è true; il campo è omesso nell’ultima pagina. |
Esplori gli schemi OpenAPI live su /docs, esegua test con la nostra collezione Bruno in Test e debug oppure progetti modelli di pass con l'AI in Crei il Suo primo pass Wallet.
