A shell like bash can be used to make adhoc CLI queries against REST API’s and create powerful utility scripts to automate complex operations. It is standard on most systems such as Mac’s, Android, Linux, and optional on Windows10.

CLI tools

curl

curl is a powerful commandline tool and library for transferring data using URL syntax available on Mac, Windows, Linux, UNIX. It can be used to submit complex REST & SOAP requests on the comandline or within a wide range of programming languages.

jq

jq is a light weight and flexible command-line JSON processor. It can be used to extract and reformat the parts of a JSON response that we are interested in.

REST CLI

connection details for the demo site
API='https://oms.economicoutlook.net/demo/apis/rest/admin' UP='guest:nosecret'
list people (just their IDs)
curl -s -u $UP "$API/people"
list people matching search query
curl -s -u $UP "$API/people?query=adrian@econom"
search for a persons basic details
curl -s -u $UP "$API/people?query=adrian@econom" --header "Accept:application/vnd.eo.person+json"
fetch their details
PERSONID=ba0edc5a-6d73-4889-8e81-2f328f7071bc
curl -s -u $UP "$API/people/$PERSONID" --header "Accept:application/vnd.eo.person+json"
include extended attributes and tags
curl -s -u $UP "$API/people/$PERSONID" --header "Accept:application/vnd.eo.personplus+json"
same in XML
curl -s -u $UP "$API/people/$PERSONID" --header "Accept:application/vnd.eo.personplus+xml"
find the membership groups UUID
UP='guest:nosecret'
curl -s -u $UP '$API/groups/memberships'
get UUIDs of people in the group
GROUPID=744fb3bd-35a1-44f4-8c82-4ca8ac78f3d8
curl -s -u $UP "$API/people?groupId=$GROUPID"
save details of people in the group
curl -s -u $UP "$API/people?groupId=$GROUPID" --header "Accept:application/vnd.eo.person+json" -o results.json
filter to create a simple maillist
jq '.response.people[].email' results.json | grep @ | tr -d \"
filter to construct a fancy maillist
jq '.response.people[] | .firstNames + " " + .lastName + " <" + .email + ">"' results.json  | grep @ | tr -d \"

REST script

oms-shell-rest-demo.sh
#!/bin/sh

STUB !!!

SOAP script

Bash script SOAP example (OMS)

Get a list of available reports in XML

oms-shell-soap-demo.sh
#!/bin/sh
CLIENT="demo"
USER="guest"
PASSWORD="nosecret"

NAMESPACE="http://omsviewer.server.economicoutlook.net/"
SOAPSERVICE="apis/soap/omsviewer"
TRANS="getReportsList"
PARAMETERS=""

DISPLAYPROG=$(which tidy 2>/dev/null && echo '-q -i -xml' || echo 'cat -' )

SOAP_COMMAND='<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:'$TRANS' xmlns:ns2="'$NAMESPACE'">'$PARAMETERS'</ns2:'$TRANS'>
</S:Body>
</S:Envelope>
'

echo --- sent ---
echo $SOAP_COMMAND | $DISPLAYPROG
echo
echo --- received ---
curl -s https://oms.economicoutlook.net/$CLIENT/$SOAPSERVICE \
     --user $USER:$PASSWORD \
     --header 'Content-type: text/xml;charset="utf-8"' \
     --data-binary "$SOAP_COMMAND" \
     | $DISPLAYPROG