put scripts in ./scripts

This commit is contained in:
Steve White 2024-10-10 20:38:57 -05:00
parent 5c91623d25
commit 61f30677e8
7 changed files with 37 additions and 0 deletions

37
scripts/getboxes.bash Normal file
View File

@ -0,0 +1,37 @@
#!/bin/bash
# API base URL
API_BASE_URL="http://10.0.0.66:8080"
# Login credentials
USERNAME="boxuser"
PASSWORD="boxuser"
# Function to make an authenticated request
function authenticated_request() {
local method=$1
local endpoint=$2
local data=$3
# Get a new JWT token
TOKEN=$(curl -s -X POST -H "Content-Type: application/json" \
-d "{\"username\":\"$USERNAME\", \"password\":\"$PASSWORD\"}" \
"$API_BASE_URL/login" | jq -r '.token')
# Make the authenticated request
curl -s -X $method -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$data" \
"$API_BASE_URL$endpoint"
}
# Get all boxes
response=$(authenticated_request "GET" "/boxes" "")
# Check if the request was successful
if [[ $? -eq 0 ]]; then
# Pretty print the boxes using jq
echo "$response" | jq .
else
echo "Error: Failed to get boxes."
fi