Hi all,
Since Mango 3.3 introduces the use of JWT tokens for authentication, I decided that using the REST API is a bit more appealing. So I decided to write a little utility to make it easier to query.
mangocli
is written in Bash and uses (https://curl.haxx.se/) and jq.
You can review the code and download it here: https://github.com/iA3io/mangocli
This is an open source tool and you are free to use and modify it however you see fit. I hope you find it helpful.
More information is in the README in the Git repo but here is a snippet:
Example Usage
Query all data points
$ mangocli -a ./jwt-token data-points
The default HTTP action is GET. The default host is http://localhost:8080.
Create a new data point
$ mangocli -a ./jwt-token -d @./new-point.json data-points
The -d
option is just the --data
option for curl
. The @
prefix causes
the argument to be parsed as a file. Using the -d
option changes the default
HTTP action to POST.
Enable and restart a data point
$ mangocli -a ./jwt-token -u enabled=true -u restart=true PUT data-points/enable-disable/DP_XID
Using the -u
option defines a URL query parameter.
Delete a data point.
$ mangocli -a ./jwt-token DELETE data-points/DP_XID
Manual
Usage: mangocli [OPTION...] [ACTION] PATH
Options:
-h HOST HOST is the domain name or IP address of the Mango server.
Can be set using the environment variable MANGOCLI_HOST.
Defaults to 'http://localhost:8080' if not specified.
A HOST without a specified protocol will default to HTTPS.
-a AUTH AUTH is the JWT token or the path to a file containing it.
Can be set using the environment variable MANGOCLI_AUTH
-d DATA DATA to include in the body of a request. Can be specified multiple times.
Use `-d @-' to read from stdin or `-d @filename' to read from a file.
Equivalent to `curl --data="DATA"'. Changes default ACTION to POST.
-u PARAM PARAM is URL encoded data. Can be specified multiple times.
Using this option will pass all data as URL parameters.
Use `-u @-' to read from stdin or `-u @file' to read from a file.
Equivalent to `curl --get --data-urlencode="PARAM"'.
-C CURL_OPTS CURL_OPTS is a space separated list of additional options to pass to curl.
Can be specified multiple times.
-V VERSION VERSION is the REST API version number: 1 or 2.
Can be set using the environment variable MANGOCLI_VERSION.
Defaults to v2.
-c Compact JSON output. Removes all whitespace.
-v Increase verbosity. Once for info, twice for debug output.
-q Quiet mode. Suppresses all error, info and debug messages.
Overrides any `-v' options.
Arguments:
ACTION The HTTP action: GET, POST, PUT, DELETE
Defaults to GET.
PATH The path or route for the request