Skip to content

Published passports of a model

List every unit of a battery model with a published passport and print passport id, current version and public link as CSV.

The script lists the units of one battery model whose passport is published, with listBatteries and the filters battery_model_id and passport_status=published, then reads each passport with getPassport and prints one CSV row per unit: serial number, passport id, current version, publication time and public page. It needs a key with the scope read.

  • The model id comes from listBatteryModels.
  • Passports in update_needed are online too (their current version stays public until they are published again). Run the script a second time with passport_status=update_needed to include them.
  • To narrow it to one model version, use model_version_id instead of battery_model_id.
#!/usr/bin/env bash
# model-passports.sh <model-id>: the published passports of one battery model as CSV (needs curl and jq)
set -euo pipefail
model_id="$1" # the id from listBatteryModels
auth="Authorization: Bearer $BATTERYPASS_API_KEY"
echo "serial_number,passport_id,version_no,published_at,public_url"
cursor=""
while :; do
  page=$(curl -sS --fail --retry 5 -G "$BATTERYPASS_URL/api/v1/batteries" -H "$auth" \
    -d "battery_model_id=$model_id" -d passport_status=published -d limit=200 \
    ${cursor:+--data-urlencode "cursor=$cursor"})
  for id in $(jq -r '.items[].id' <<<"$page"); do
    curl -sS --fail --retry 5 -H "$auth" "$BATTERYPASS_URL/api/v1/batteries/$id/passport" |
      jq -r '[.serial_number, .passport_id, .current_version.version_no, .current_version.published_at, .public_url] | @csv'
  done
  cursor=$(jq -r '.next_cursor // empty' <<<"$page")
  [ -n "$cursor" ] || break
done
Output
serial_number,passport_id,version_no,published_at,public_url
SV2027-000184,urn:dpp:0192f0c4-7d1e-7a3b-9c55-2f1e8d4a6b10,4,2026-10-24T06:00:03Z,https://batterypass.example.com/pass/0192f0c4-7d1e-7a3b-9c55-2f1e8d4a6b10
SV2027-000185,urn:dpp:0192f0d7-3e2a-7b1c-8d4e-5f6a7b8c9d0e,2,2026-09-30T14:22:10Z,https://batterypass.example.com/pass/0192f0d7-3e2a-7b1c-8d4e-5f6a7b8c9d0e

The shell version quotes every CSV field (@csv); the others quote only where needed. Each unit costs one request, and all keys of your organisation share 600 requests per minute. The passport and its versions are explained in Passports and versions.