Testing StorageGRID REST API using Window 10+ CMD and Curl

Firstly, we need to get the authorization token.

You'll need a username and password, like the root username and password you use to login to Grid Manager.

## Get authorization token:

curl -k -X POST https://YOURGRID.DOMAIN.COM/api/v4/authorize -H "accept: application/json" -H "Content-Type: application/json" -d "{\"username\":\"root\",\"password\":\"YOURPASSWORD\",\"cookie\":true,\"csrfToken\":false}"

## Note: Windows CMD doesn't support strings with single quotes. Use " and escape the inner ones with \".

The authorization token will be alphanumeric with a number of digits (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).

Now we have our authorization key, we can do stuff with it, like:

## Get grid version:

curl -k -X GET https://YOURGRID.DOMAIN.COM/api/v4/grid/config/product-version -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

## Get Service IDs (needed for the next step):

curl -k -X GET https://YOURGRID.DOMAIN.COM/api/v4/grid/service-ids -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

## Get Model, Compute Node serial number, Appliance serial number (using: SSM id XXXXXXXX from the above output):

curl -k -X GET https://YOURGRID.DOMAIN.COM/api/v4/private/attributes/SAMD/node/XXXXXXXX -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

curl -k -X GET https://YOURGRID.DOMAIN.COM/api/v4/private/attributes/CNSN/node/XXXXXXXX -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

curl -k -X GET https://YOURGRID.DOMAIN.COM/api/v4/private/attributes/APSN/node/XXXXXXXX -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

## Note: Private StorageGRID APIs are subject to change without notice.

Finally, we should de-authorize our token.

## Delete authorization:

curl -k -X DELETE https://YOURGRID.DOMAIN.COM/api/v4/authorize -H "accept: application/json" -H "Authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"



TIP: JSON outputs are not very usable in the Windows Command Prompt. Much better to type:

powershell

And run curl.exe (Note that curl in PowerShell is not the same as curl in the Command Prompt, curl in PowerShell is actually Invoke-WebRequest, whilst curl.exe is CMD's curl).

Then you can do something like:

[String]$myStr = curl.exe -k -X GET ...

And -

$mystr | ConvertFrom-JSon

- will give you a nice easy to read output.

Bonus Stuff: SANtricity and BMC REST APIs

If you have something like an SG6060 or SG6160, then you might also want to get information from SANtricity and the computer controller BMC. Here are some examples:

## SANTRICITY REST API EXAMPLE:

curl.exe -k -X GET https://CONTROLLERIPorFQDN/devmgr/v2/storage-systems -u admin:YOURPASSWORD

## BMC REST API EXAMPLE (Redfish):

curl.exe -k -X GET https://BMCIPorFQDN/redfish/v1
curl.exe -k -X GET https://BMCIPorFQDN/redfish/v1/Systems -u root:******
curl.exe -k -X GET https://BMCIPorFQDN/redfish/v1/Systems/Self -u root:******

A fairly popular request is MAC addresses, to get MAC addresses from StorageGRID, SANtricity and BMC, the relevant APIs are:

# StorageGRID: /api/v4/private/network-topology
# SANtricity: /devmgr/v2/storage-systems/{system-id}/configuration/ethernet-interfaces
# BMC: /redfish/v1/Managers/Self/EthernetInterfaces/bond0

THE END

Comments