44 lines
1.4 KiB
Bash
44 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
API_URL="https://beta4-api.ordrestyring.dk/graphql"
|
|
KEY_FILE="$ROOT_DIR/apikey"
|
|
|
|
if [[ ! -f "$KEY_FILE" ]]; then
|
|
echo "apikey file not found at $KEY_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
API_KEY_RAW=$(tr -d '\r\n' < "$KEY_FILE" || true)
|
|
# Strip surrounding backticks or markdown fences if present and extract a token-like substring
|
|
API_KEY=$(echo "$API_KEY_RAW" | sed -n 's/^\s*`*\s*\([^`[:space:]]\+\)\s*`*\s*$/\1/p' || true)
|
|
if [[ -z "$API_KEY" ]]; then
|
|
# fallback: take first non-empty token
|
|
API_KEY=$(echo "$API_KEY_RAW" | tr -s '[:space:]' '\n' | sed -n '1p' || true)
|
|
fi
|
|
|
|
# Sample GraphQL query (first page with limit 1)
|
|
PAYLOAD='{"query":"query { cases(pagination: {cursor: null, limit: 1}, orderBy: {field: \"updatedAt\", direction: DESC}) { items { id caseNumber } nextCursor previousCursor } }"}'
|
|
|
|
echo "Calling $API_URL with provided API key..."
|
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
if command -v jq >/dev/null 2>&1; then
|
|
curl -sS -X POST "$API_URL" \
|
|
-H "Authorization: Bearer $API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Accept: application/json" \
|
|
--data "$PAYLOAD" | jq '.'
|
|
else
|
|
curl -sS -X POST "$API_URL" \
|
|
-H "Authorization: Bearer $API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Accept: application/json" \
|
|
--data "$PAYLOAD"
|
|
fi
|
|
else
|
|
echo "curl is required to run this script" >&2
|
|
exit 1
|
|
fi
|