# 🐚 Bash One-Liners

For sysadmins who prefer the terminal, you can interact with TunnelSats using standard `curl` and `jq`.

### 1. Get a Lightning Invoice
Generate a 1-month invoice for a specific region directly to your console.

```bash
# Path: /api/public/v1/subscription/create
curl -s -X POST https://tunnelsats.com/api/public/v1/subscription/create \
  -H "Content-Type: application/json" \
  -d '{"serverId": "eu-de", "duration": 1}' | jq -r '.invoice'
```
[Create Subscription](https://api.tunnelsats.com/create-a-new-vpn-subscription-4063129e0.md)

### 2. Check Payment Status
Replace `<payment_hash>` with the hash returned from the previous step.

```bash
# Path: /api/public/v1/subscription/<hash>
curl -s https://tunnelsats.com/api/public/v1/subscription/<payment_hash> | jq .status
```
[Check Status / Heal](https://api.tunnelsats.com/4063130e0.md)

### 3. Claim & Save Config (Dual-Key Support)
Once paid, run this to save your WireGuard config. Note that we handle both `.fullConfig` and `.config` keys to ensure compatibility.

```bash
# Path: /api/public/v1/subscription/claim
curl -s -X POST https://tunnelsats.com/api/public/v1/subscription/claim \
  -H "Content-Type: application/json" \
  -d '{"paymentHash": "<payment_hash>"}' | jq -r '.fullConfig // .config' > tunnelsatsv2.conf
```
[Claim Subscription](https://api.tunnelsats.com/claim-a-wireguard-configuration-after-payment-4063131e0.md)

### 4. List All Subscriptions (Snake Case Alert)
When listing all subscriptions for an authenticated account, the API returns **snake_case** keys (e.g., `payment_hash` instead of `paymentHash`).

```bash
# Path: /api/public/v1/subscription/list
# Requires Authorization header (Bearer sk_live_... or Nostr base64_event)
curl -s -X GET https://tunnelsats.com/api/public/v1/subscription/list \
  -H "Authorization: Bearer <your_api_key>" | jq -r '.subscriptions[].payment_hash'
```

### 5. Auto-Renewal Cron Job
Add this script to your crontab to check expiry and generate a new invoice if needed.

```bash
#!/bin/bash
HASH="<your_payment_hash>"
API="https://tunnelsats.com/api/public/v1"

# Lookup uses camelCase: .subscriptionEnd
STATUS=$(curl -s "$API/subscription/$HASH")
EXPIRY=$(echo $STATUS | jq -r '.subscriptionEnd')
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

if [[ "$NOW" > "$EXPIRY" ]]; then
  echo "⚠️ Subscription Expired! Renewing..."
  # Add renewal logic here
else
  echo "✅ VPN Active. Expires: $EXPIRY"
fi
```