Developing a client application by using the curl tool

curl is a cross-platform command-line data transfer tool that works well with REST transactions. Mozilla Firefox and Google Chrome can record the browser’s HTTP requests and transform the requests into a curl command format. In a shell session, you can invoke the curl command and combine it with other text-processing commands such as grep. Although working with shell sessions is not suitable for processing large JSON records, it is a good approach to capture a browser’s HTTP request in the curl format and modify it to generalize the structure before you actually code them in the production environment such as Python and Java.

This section describes how you can retrieve any actions on the IBM Spectrum Protect Plus web user interface on Mozilla Firefox or Google Chrome, capture their HTTP requests in the curl format, and then reuse them from your shell session. curl supports many platforms, for example:

  • Bash on Linux® and Microsoft Windows Subsystems for Linux (WSL) 1

  • Z Shell on Apple macOS series

  • PowerShell Core and Microsoft Windows PowerShell and Command shell

For more information about curl, see the following documentation:

Capturing HTTP requests on a web browser

IBM Spectrum Protect Plus offers two user interfaces: the web user interface and the REST API. For scripting, you can take the following approach:

  1. From a supported browser, take the action that you want to script and determine the simplest path.

  2. Complete the action with multiple scenarios while capturing HTTP transactions.

  3. Review the HTTP transactions that you captured.

  4. Script the HTTP requests and handle the expected responses.

The supported browsers (Mozilla Firefox, Google Chrome, and Microsoft Edge) have a developer tool that can be used to capture HTTP transactions.

Before you begin

To review the web browsers that are supported for IBM Spectrum Protect Plus Version 10.1.8, see System requirements: IBM Spectrum Protect Plus.

In Mozilla Firefox, open Firefox Developer Tools. Click the Network tab. Click the Pause/Resume recording network log button to capture HTTP requests. Take the action that you want to script in the IBM Spectrum Protect Plus web user interface. Click the button again to stop capturing further HTTP requests. Find the relevant HTTP request in the list. Right-click the request, click Copy > Copy as cURL (POSIX). Ensure that the curl command that you have copied works as you expect. Paste the command into a text editor and examine it.

In Google Chrome, you can capture HTTP requests in a similar way as in the example with Mozilla Firefox. Open DevTools. Click the Network tab. Click Record network log. In the IBM Spectrum Protect Plus web user interface, take the actions that you want to script. Click Pause recording network log. Find the relevant HTTP request in the list. Right-click the request, click Copy > Copy as cUrl (bash). Ensure that the curl command you copied works as you expect. Paste the command into a text editor and examine it.

Example: Start an inventory job for hypervisor instances

The following example shows how to capture an HTTP request to invoke an inventory job for hypervisors: VMware or Microsoft Hyper-V.

In your web browser, log in to IBM Spectrum Protect Plus (IPv4 address 10.0.0.100). In the navigation pane, click Manage Protection > Hypervisors > VMware. Turn on recording for a network log. Click Run Inventory. Turn off the recording mode.

In Mozilla Firefox 81 for Windows 10, for example, you will get the HTTP request and copy it into your system clipboard as a single curl command for POSIX:

curl 'https://10.0.0.100/api/endeavour/job/1004?action=start&actionname=start' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) \
      Gecko/20100101 Firefox/81.0' \
  -H 'Accept: application/json' \
  -H 'Accept-Language: en-US,en;q=0.5' \
  --compressed \
  -H 'Content-Type: application/json'\
  -H 'X-endeavour-auditrequest: true' \
  -H 'X-Endeavour-Sessionid: 8b56b813936a4957be1db80ca8a8ea0c' \
  -H 'X-Endeavour-Locale: en-us' \
  -H 'Origin: https://10.0.0.100' \
  -H 'DNT: 1' \
  -H 'Connection: keep-alive' \
  -H 'Referer: https://10.0.0.100/' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  --data ''

The curl command is equivalent to the following HTTP request:

Method: POST

URI: https://10.0.0.100/api/endeavour/job/1004

Parameters:

Key

Value

action

start

actionname

start

Tip

URIs are typically encoded with ASCII characters and can include parameters. For information about the syntax of URIs, see the following document, including its errata: Uniform Resource Identifier (URI): Generic Syntax, IETF RFC 3986.

For instructions about decoding URIs, see the following topics:

Data: None.

Header:

Key

Value

Accept

application/json

Content-Type

application/json

X-Endeavour-Sessionid

8b56b813936a4957be1db80ca8a8ea0c

Options:

  • --compressed

See also

For more information about the relevant REST API request command, follow the instructions in Running an inventory job for virtualized systems.