#!/usr/bin/env bash # API Client for Ordrestyring # Configuration DATA_DIR="${DATA_DIR:-./ordrestyring_export}" REPORTS_DIR="${REPORTS_DIR:-./reports}" # API endpoints API_BASE="https://app.ordrestyring.dk/api/rest/v1" # Fetch all cases from API fetch_all_cases() { local api_key="$1" echo "Henter cases fra API..." curl -s -H "Authorization: Bearer $api_key" \ -H "Content-Type: application/json" \ "$API_BASE/cases" > "$DATA_DIR/all_cases.json" # Convert to JSONL format if [[ -f "$DATA_DIR/all_cases.json" ]]; then jq -c '.[]' "$DATA_DIR/all_cases.json" > "$DATA_DIR/all_cases.jsonl" 2>/dev/null || true echo "Cases hentet: $(wc -l < "$DATA_DIR/all_cases.jsonl" 2>/dev/null || echo "0")" fi } # Fetch hours data from API fetch_hours_data() { local api_key="$1" echo "Henter timer data fra API..." curl -s -H "Authorization: Bearer $api_key" \ -H "Content-Type: application/json" \ "$API_BASE/registrations/hours" > "$DATA_DIR/hours_data.json" # Convert to JSONL format if [[ -f "$DATA_DIR/hours_data.json" ]]; then jq -c '.[]' "$DATA_DIR/hours_data.json" > "$DATA_DIR/hours_data.jsonl" 2>/dev/null || true echo "Timer registreringer hentet: $(wc -l < "$DATA_DIR/hours_data.jsonl" 2>/dev/null || echo "0")" fi } # Get case details by ID get_case_details() { local api_key="$1" local case_id="$2" curl -s -H "Authorization: Bearer $api_key" \ -H "Content-Type: application/json" \ "$API_BASE/cases/$case_id" } # Get hours for specific case get_case_hours() { local api_key="$1" local case_id="$2" curl -s -H "Authorization: Bearer $api_key" \ -H "Content-Type: application/json" \ "$API_BASE/cases/$case_id/hours" }