Files
klipper-macros/macros/bd_pa_write_spoolman.sh
T

22 lines
617 B
Bash
Raw Normal View History

#!/bin/bash
SPOOL_ID=$1
BASE_URL=$2
FIELD=$3
PA_VALUE=$4
CURRENT=$(curl -sf "${BASE_URL}/api/v1/spool/${SPOOL_ID}" 2>/dev/null)
EXTRA=$(echo "$CURRENT" | python3 -c "
import sys, json
try:
d = json.load(sys.stdin)
e = d.get('extra', {})
e['$FIELD'] = '$PA_VALUE'
print(json.dumps(e))
except Exception:
print(json.dumps({'$FIELD': '$PA_VALUE'}))
" 2>/dev/null)
if [ -z "$EXTRA" ]; then
EXTRA="{\"$FIELD\": \"$PA_VALUE\"}"
fi
curl -sf -X PATCH "${BASE_URL}/api/v1/spool/${SPOOL_ID}" \
-H "Content-Type: application/json" \
-d "{\"extra\": $EXTRA}" > /tmp/pa_spoolman_write_result 2>&1