Last active
December 2, 2021 18:08
-
-
Save leoheck/430698751f17d679d5e9b142280cb03c to your computer and use it in GitHub Desktop.
Shellhub API Requests with Curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#============================================ | |
# GET ACCESS TOKEN | |
read -r -d '' login_data <<-EOM | |
{ | |
"username": "${SHELLHUB_USER}", | |
"password": "${SHELLHUB_PASS}" | |
} | |
EOM | |
TOKEN=$(curl -s -X POST \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
--data "${login_data}" \ | |
"${URL}/api/login" | jq -r '.token') | |
#============================================= | |
# GET NAMESPACES | |
read -r -d '' data <<-EOM | |
{ | |
"page": "0", | |
"per_page": "0" | |
} | |
EOM | |
curl -s -X GET \ | |
-H 'Accept: application/json' \ | |
-H "Authorization: Bearer ${TOKEN}" \ | |
-H "X-total-count: 10" \ | |
--data "${data}" \ | |
"${URL}/api/namespaces" | |
#============================================= | |
# SELECT/CHANGE THE NAMESPACE | |
TOKEN=$(curl -s -X GET \ | |
-H 'Accept: application/json' \ | |
-H "Authorization: Bearer ${TOKEN}" \ | |
"${URL}/api/auth/token/${tenant_id}" | jq -r '.token') | |
#============================================ | |
# GET DEVICES LIST | |
read -r -d '' data <<-EOM | |
{ | |
"page": "0", | |
"per_page": "0" | |
} | |
EOM | |
curl -s -X GET \ | |
-H 'Accept: application/json' \ | |
-H "Authorization: Bearer ${TOKEN}" \ | |
-H "X-total-count: 100" \ | |
--data "${data}" \ | |
"${URL}/api/devices" | |
#============================================= | |
# GET SESSIONS | |
read -r -d '' data <<-EOM | |
{ | |
"page": "0", | |
"per_page": "0" | |
} | |
EOM | |
curl -s -X GET \ | |
-H 'Accept: application/json' \ | |
-H "Authorization: Bearer ${TOKEN}" \ | |
-H "X-total-count: 10" \ | |
--data "${data}" \ | |
"${URL}/api/sessions" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment