Petnow LogoPetnow

API v1 to v2 Migration

Guide for migrating from Petnow API v1 to v2.

Overview

API v2 introduces the Capture Session concept, streamlining how fingerprint and appearance images are processed. This guide helps you migrate from v1 to v2.

Key Changes

Capture Session Introduction

In v1, metadata (species, purpose) was passed with each file upload. In v2, you first create a capture session and then upload files within that session.

AspectAPI v1API v2
MetadataPassed with each uploadSet once at session creation
File GroupingManual ID managementAutomatic via session
Action RequestList of file IDsSession ID only

Endpoint Changes

Functionv1 Endpointv2 Endpoint
Fingerprint UploadPOST /v1/fingerprints:uploadPOST /v2/fingerprints:upload
Appearance UploadPOST /v1/appearances:uploadPOST /v2/appearances:upload
Pet VerifyPOST /v1/pets/{petId}:verifyPOST /v2/pets/{petId}:verify
Pet IdentifyPOST /v1/pets:identifyPOST /v2/pets:identify
Add FingerprintsPOST /v1/pets/{petId}:addFingerprintsPOST /v2/pets/{petId}:addFingerprints
New-POST /v2/capture-sessions

Workflow Comparison

v1 Workflow

v2 Workflow

Automatic Session Linking: When uploading with the sessionId query parameter, files are automatically linked to the session. No separate session end API call is required, and all files in the session are automatically used when performing actions (verify, identify, addFingerprints).

Code Migration Example

v1 Code (Before)

// v1: Pass metadata with each upload
const fp1 = await fetch('/v1/fingerprints:upload', {
  method: 'POST',
  body: createFormData({
    file: file1,
    species: 'DOG',
    purpose: 'PET_VERIFICATION'
  })
}).then(r => r.json());

const fp2 = await fetch('/v1/fingerprints:upload', {
  method: 'POST',
  body: createFormData({
    file: file2,
    species: 'DOG',
    purpose: 'PET_VERIFICATION'
  })
}).then(r => r.json());

// v1: Verify with file ID list
const verifyResult = await fetch(`/v1/pets/${petId}:verify`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    fingerprints: [fp1.data.id, fp2.data.id]
  })
}).then(r => r.json());

v2 Code (After)

// v2: Create session (metadata once)
const session = await fetch('/v2/capture-sessions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    species: 'DOG',
    purpose: 'PET_VERIFICATION',
    petId: petId
  })
}).then(r => r.json());

// v2: Upload files (automatically linked with sessionId query parameter)
const fp1 = await fetch(`/v2/fingerprints:upload?sessionId=${session.data.sessionId}`, {
  method: 'POST',
  body: createFormData({ file: file1 })
}).then(r => r.json());

const fp2 = await fetch(`/v2/fingerprints:upload?sessionId=${session.data.sessionId}`, {
  method: 'POST',
  body: createFormData({ file: file2 })
}).then(r => r.json());

// v2: Verify with session ID (all uploaded files automatically used)
const verifyResult = await fetch(`/v2/pets/${petId}:verify`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    sessionId: session.data.sessionId
  })
}).then(r => r.json());

Session States

Capture sessions have the following states:

StateDescription
STARTEDSession is active and ready to receive uploads
FINISHEDSession successfully closed with captured data
ABORTEDSession was cancelled or failed
TIMEOUTSession expired without proper closure

Upload Requirements

OperationMinimum Fingerprints
Registration5
Verification3
Identification3

Migration Checklist

  • Add session creation logic (POST /v2/capture-sessions)
  • Add sessionId query parameter to file upload URLs
  • Remove species, purpose metadata from file upload request body
  • Use session ID instead of file ID list in verify/identify requests
  • Remove session end logic (automatically handled)
  • Add session-related error handling
  • Update endpoint URLs from /v1/ to /v2/

v2 Benefits

  1. Simplified Metadata: Set species and purpose once at session creation
  2. Better Tracking: All uploads for an operation are automatically grouped
  3. Enhanced Validation: Minimum requirements checked before processing
  4. Extensibility: Session-based architecture supports progress tracking, resumable uploads, etc.

Common Migration Errors

Upload Without Session

{
  "error": "Session context is required"
}

Solution: Create a capture session before uploading files.

Missing sessionId Query Parameter

{
  "error": "Session ID is required"
}

Solution: Add ?sessionId={sessionId} query parameter to upload URL.

Missing Pet ID for Verification

{
  "error": "Pet ID is required for verification purpose"
}

Solution: Include petId when creating the capture session.

On this page