Skip to content

Instantly share code, notes, and snippets.

@nklamann
Created June 4, 2024 12:42
Show Gist options
  • Save nklamann/dbb4a859eae3dde15727de3526587181 to your computer and use it in GitHub Desktop.
Save nklamann/dbb4a859eae3dde15727de3526587181 to your computer and use it in GitHub Desktop.
OMADA openapi calls demonstration
### Bash Example
# set variables
OMADA_URL="https://omada:8043"
USERNAME="Viewer"
PASSWORD="grundlos"
CLIENT_ID="fb355d589ebf4b798415ca612d99819a" # from application list
CLIENT_SECRET="1c369a99a1574b5d8ed959c6e88b9565" # from application list
OMADA_ID="c491b4a4d05ff0d58282f4645848e9ec" # from view open api attributes
curl -s "${OMADA_URL}/openapi/authorize/login?client_id=${CLIENT_ID}&omadac_id=${OMADA_ID}" \
-H 'content-type:application/json' -d "{\"username\":\"${USERNAME}\",\"password\":\"${PASSWORD}\"}" -k --insecure > /tmp/login.json
CSRFTOKEN=$(cat /tmp/login.json | jq -r .result.csrfToken )
SESSIONID=$(cat /tmp/login.json | jq -r .result.sessionId )
cat /tmp/login.json | jq
echo "CSRFTOKEN=${CSRFTOKEN}"
echo "SESSIONID=${SESSIONID}"
curl -s "${OMADA_URL}/openapi/authorize/code?client_id=${CLIENT_ID}&omadac_id=${OMADA_ID}&response_type=code" \
-H 'content-type:application/json' -H "Csrf-Token:${CSRFTOKEN}" -H "Cookie:TPOMADA_SESSIONID=${SESSIONID}" -X POST -k --insecure > /tmp/authcode.json
AUTHCODE=$(cat /tmp/authcode.json | jq -r .result)
cat /tmp/authcode.json | jq
echo "AUTHCODE=${AUTHCODE}"
curl -s "${OMADA_URL}/openapi/authorize/token?grant_type=authorization_code&code=${AUTHCODE}" \
-H 'content-type:application/json' -d "{\"client_id\": \"${CLIENT_ID}\", \"client_secret\": \"${CLIENT_SECRET}\"}" -X POST -k --insecure > /tmp/token.json
ACCESSTOKEN=$(cat /tmp/token.json | jq -r .result.accessToken )
REFRESHTOKEN=$(cat /tmp/token.json | jq -r .result.refreshToken )
cat /tmp/token.json | jq
echo "ACCESSTOKEN=${ACCESSTOKEN}"
echo "REFRESHTOKEN=${REFRESHTOKEN}"
## example
curl -s "${OMADA_URL}/openapi/v1/${OMADA_ID}/sites?pageSize=1&page=1" -H 'content-type:application/json' -H "Authorization:AccessToken=${ACCESSTOKEN}" -X GET -k --insecure | jq
@bordzee
Copy link

bordzee commented Jun 14, 2024

Theres no voucher or hotspot endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment