Skip to content

Commit 7873050

Browse files
committed
Add shell script example
1 parent a07267a commit 7873050

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
remote_user=test
6+
remote_password=apipassword
7+
remote_url='https://yourserver.com:8080/remote/json.php'
8+
9+
# restCall method data
10+
restCall() {
11+
curl -sS -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d "${2}" "${remote_url}?${1}"
12+
}
13+
14+
# Log in
15+
session_id=`restCall login "{\"username\": \"${remote_user}\",\"password\": \"${remote_password}\"}" | jq -r '.response'`
16+
if [[ $isession == "false" ]]; then
17+
echo "Login failed!"
18+
exit 1
19+
#else
20+
#echo "Logged in. Session is: $session_id"
21+
fi
22+
23+
restCall client_get "{\"session_id\": \"$session_id\",\"client_id\":{\"username\": \"abcde\"}}"
24+
25+
# or by id
26+
restCall client_get "{\"session_id\": \"$session_id\",\"client_id\": \"2\"}"
27+
28+
# or all
29+
restCall client_get "{\"session_id\": \"$session_id\",\"client_id\":{}}"
30+
31+
# Log out
32+
if [[ `restCall logout "{\"session_id\": \"$session_id\"}" |jq -r .response` == "true" ]]; then
33+
#echo "Logout successful."
34+
exit 0
35+
else
36+
echo "Logout failed!"
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)