#!/usr/bin/env bash # HaulProof API with curl. Usage: HP_KEY=hp_test_... bash curl.sh (a sandbox key works for every call except watchlists) set -euo pipefail : "${HP_KEY:?set HP_KEY}" BASE="${HP_BASE:-https://haulproof.ca}" H=(-sS -H "Authorization: Bearer $HP_KEY") case "$HP_KEY" in hp_test_*) DOT=99990004; MC=MC990004 ;; *) DOT=264184; MC=MC133655 ;; esac echo "== tiers for 3 carriers"; curl "${H[@]}" "$BASE/v1/tiers?ids=$DOT,$MC,us:99990001"; echo echo "== one full record"; curl "${H[@]}" -D - -o /dev/null "$BASE/v1/carriers/$DOT" | grep -i -E "^HTTP|x-hp-cache" echo "== search"; curl "${H[@]}" "$BASE/v1/search?q=$DOT&limit=1"; echo echo "== tier files (signed links)"; curl "${H[@]}" "$BASE/v1/tier-files"; echo URL=$(curl "${H[@]}" "$BASE/v1/tier-files" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p' | head -1) [ -n "$URL" ] && { echo "== first rows of the file"; curl -sS "$URL" | gunzip | head -3 || true; } echo "== badge (SVG)"; curl "${H[@]}" "$BASE/v1/badges/$DOT.svg?partner=Loadlink" | head -c 160; echo echo "== create a watchlist and add carriers in bulk (live keys)" W=$(curl "${H[@]}" -X POST -H "Content-Type: application/json" -d "{\"name\":\"curl sample $(date +%s)\"}" "$BASE/v1/watchlists"); echo "$W" WID=$(echo "$W" | sed -n 's/.*"id":"\([^"]*\)".*/\1/p') [ -n "$WID" ] && curl "${H[@]}" -X POST -H "Content-Type: application/json" -d "{\"items\":[\"$DOT\",\"$MC\",\"not a carrier\"]}" "$BASE/v1/watchlists/$WID/items/bulk"; echo [ -n "$WID" ] && curl "${H[@]}" -X DELETE -o /dev/null -w "delete the sample's watchlist: HTTP %{http_code}\n" "$BASE/v1/watchlists/$WID" echo "== webhooks: add one (HP_WEBHOOK_URL, public https), send a test, remove it" if [ -n "${HP_WEBHOOK_URL:-}" ]; then WH=$(curl "${H[@]}" -X POST -H "Content-Type: application/json" -d "{\"url\":\"$HP_WEBHOOK_URL\",\"min_severity\":\"warning\"}" "$BASE/v1/webhooks"); echo "$WH" HID=$(echo "$WH" | sed -n 's/.*"id":"\([^"]*\)".*/\1/p') curl "${H[@]}" -X POST "$BASE/v1/webhooks/$HID/test"; echo curl "${H[@]}" -X DELETE -o /dev/null -w "delete webhook: HTTP %{http_code}\n" "$BASE/v1/webhooks/$HID" else echo "(set HP_WEBHOOK_URL to try)"; fi echo "== usage this month"; curl "${H[@]}" "$BASE/v1/usage"; echo