#!/usr/bin/env bash # Specto LCO API — cURL + OpenSSL example (bash 4+, curl, openssl, xxd not required). # # export SPECTO_API_BASE=https://api.spectotv.com/api/v1 # export SPECTO_API_KEY=spk_... SPECTO_API_SECRET=sps_... # ./curl.sh GET balance # ./curl.sh GET subscription 'subscriber_id=123456' # ./curl.sh POST activate '' '{"full_name":"Ravi Kumar","mobile":"9876543210","plan_id":"171839"}' order-1001 # # Arguments: METHOD ENDPOINT [QUERY(already sorted & encoded)] [JSON_BODY] [IDEMPOTENCY_KEY] set -euo pipefail METHOD="${1:?METHOD}"; ENDPOINT="${2:?ENDPOINT}"; QUERY="${3:-}"; BODY="${4:-}"; IDEM="${5:-}" BASE="${SPECTO_API_BASE%/}"; ORIGIN="${BASE%/api/v1}" PATH_="/api/v1/${ENDPOINT}" TS="$(date +%s)" NONCE="$(openssl rand -hex 16)" BODY_HASH="$(printf '%s' "$BODY" | openssl dgst -sha256 -hex | sed 's/^.*= //')" STS="$(printf '%s\n%s\n%s\n%s\n%s\n%s' "$METHOD" "$PATH_" "$QUERY" "$TS" "$NONCE" "$BODY_HASH")" SIG="$(printf '%s' "$STS" | openssl dgst -sha256 -hmac "$SPECTO_API_SECRET" -hex | sed 's/^.*= //')" ARGS=(-sS -X "$METHOD" -H "X-API-Key: $SPECTO_API_KEY" -H "X-Timestamp: $TS" -H "X-Nonce: $NONCE" -H "X-Signature: $SIG") [ -n "$IDEM" ] && ARGS+=(-H "Idempotency-Key: $IDEM") if [ "$METHOD" = "POST" ]; then ARGS+=(-H "Content-Type: application/json" --data-binary "$BODY"); fi # optional extra headers separated by '|', e.g. for your own outbound proxy if [ -n "${SPECTO_EXTRA_HEADERS_CURL:-}" ]; then IFS='|' read -ra EXTRA <<< "$SPECTO_EXTRA_HEADERS_CURL"; for h in "${EXTRA[@]}"; do ARGS+=(-H "$h"); done; fi URL="${ORIGIN}${PATH_}"; [ -n "$QUERY" ] && URL="${URL}?${QUERY}" curl "${ARGS[@]}" -w '\nHTTP %{http_code}\n' "$URL"