I’m trying to reduce the number of apk adds I use. I found by searching online there were no real solutions for clean NetCat use. I wanted it clean, and I wanted to use built-in’s only. This is a script which can replace curl. It may be slow, but for my needs it doesn’t need to be fast. This will run in hassio terminal.
echo $(nc -i 1 hassio 80 <<<unix2dos<<EOF
GET /core/api/events HTTP/1.1
Host: supervisor
User-Agent: curl/7.69.1
Accept: */*
Authorization: Bearer ${SUPERVISOR_TOKEN}
Content-Type: application/json
EOF
)|sed -e 's/.*\x0d\x20\x0d//1'
Breakdown:
echo $(nc -i 1 (HOST NAME OR IP ADDRESS) 80<<<unix2dos<<EOF
(HTTP METHOD) (API ENDPOINT) HTTP/1.1
Host: supervisor
User-Agent: curl/7.69.1
Accept: */*
Authorization: Bearer ${SUPERVISOR_TOKEN}
Content-Type: application/json
(REQUEST BODY GOES HERE FOR POST REQUESTS)
EOF
)|sed -e 's/.*\x0d\x20\x0d//1'
example of getting number of startup listeners from the supervisor into a variable called “listeners”
listeners=$(echo $(nc -i 1 hassio 80 <<<unix2dos<<EOF
GET /core/api/events HTTP/1.1
Host: supervisor
User-Agent: curl/7.69.1
Accept: */*
Authorization: Bearer ${SUPERVISOR_TOKEN}
Content-Type: application/json
EOF
)|sed -e 's/.*\x0d\x20\x0d//1'|jq '.[]|select(.event=="homeassistant_start").listener_count')