# cURL

> Every endpoint from the command line, and a complete sandbox run.

```bash
export OTP_PS_API_KEY=otp_test_…   # from the dashboard

# Send
curl https://otp.ps/api/v1/verify/send \
  -H "Authorization: Bearer $OTP_PS_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-otp-1" \
  -d '{"phone": "0599123456", "purpose": "order", "locale": "ar"}'

# Check
curl https://otp.ps/api/v1/verify/check \
  -H "Authorization: Bearer $OTP_PS_API_KEY" -H "Content-Type: application/json" \
  -d '{"id": "ver_…", "code": "4821"}'

# Status and balance
curl https://otp.ps/api/v1/verify/ver_… -H "Authorization: Bearer $OTP_PS_API_KEY"
curl https://otp.ps/api/v1/balance -H "Authorization: Bearer $OTP_PS_API_KEY"
```

## Complete sandbox run

Tested against the API on every change.

```bash title="examples/curl/sandbox-flow.sh"
#!/usr/bin/env bash
# The whole flow with a test key: no message is sent and nothing is charged.
#   OTP_PS_API_KEY=otp_test_… ./sandbox-flow.sh
set -euo pipefail
BASE="${OTP_PS_BASE_URL:-https://otp.ps}"
AUTH="Authorization: Bearer ${OTP_PS_API_KEY:?Set OTP_PS_API_KEY to a test key}"

# 1. Send a code to the sandbox number (its code is always 1234).
SEND=$(curl -sS "$BASE/api/v1/verify/send" -H "$AUTH" -H "Content-Type: application/json" \
  -H "Idempotency-Key: sandbox-$(date +%s)" \
  -d '{"phone": "0599000001", "purpose": "verify", "locale": "en"}')
echo "$SEND"
ID=$(printf '%s' "$SEND" | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')

# 2. A wrong code: valid is false, attempts_left goes down.
curl -sS "$BASE/api/v1/verify/check" -H "$AUTH" -H "Content-Type: application/json" -d "{\"id\": \"$ID\", \"code\": \"0000\"}"
echo

# 3. The right code: valid is true.
curl -sS "$BASE/api/v1/verify/check" -H "$AUTH" -H "Content-Type: application/json" -d "{\"id\": \"$ID\", \"code\": \"1234\"}"
echo
```
