Description

The CSO HTTP APIs are available through endpoints to which a user can send HTTP requests. For each operation that maps to a remote procedure call (RPC), the request pattern is as follows:

  • HTTP-method: Specifies the type of operation. The methods can be: GET, PUT, POST, or DELETE.
  • Body: Includes the JavaScript Object Notation (JSON) object.
  • Response: Begins with the parent parameter "output".

This article describes how to execute CSO HTTP Rest API's using Postman API client. The provided example is based on CSO 5.1.2.

This KB is provided as example instructions for Postman. 

More information on installing Postman client can be found at https://www.postman.com/downloads/

Solution

  1. Launch the Postman desktop client and click on Settings

  2. Make sure the Settings, especially 'SSL certificate verification' and 'Retain Headers when clicking links' are adjusted as shown below:

  3. As mentioned in KB34116 [juniper.net] the first step is to get the token to authenticate further CSO Rest API requests.

    Tokens can be generated in different ways:

    • Get the token from browser if user already logged in to the CSO Portal. Refer to KB36596 [juniper.net].
    • Get the token using curl commands in CLI. Refer to KB34116 [juniper.net].
    • Get the token using Postman client. For this, go to Step 4.
  1. Generate a token:

    1. Send a Post request:

      URL: http://CSO IP Address:5000/v3/auth/tokens
      CSO IP Address => CSO VIP IP if CSO deployed in HA mode or CSO baremetal server IP if CSO deployed in standalone mode

      Method: Post
      Headers:

      Content-Type = applicatoin/json
      Used Json body as shown in examples below depending on token scope.

      Global scoped token:

        {
    "auth": {
        "scope": {
            "project": {
                "domain": {
                    "id": "default"
                },
                "name": "admin"
            }
        },
        "identity": {
            "password": {
                "user": {
                    "domain": {
                        "id": "default"
                    },
                    "password": "$ABC123",
                    "name": "cspadmin"
                }
            },
            "methods": [
                "password"
            ]
        }
    }
}

Tenant Scoped Token:
 
     {
    "auth": {
        "scope": {
            "project": {
                "domain": {
                    "id": "default"
                },
                "name": "TenantA"
            }
        },
        "identity": {
            "password": {
                "user": {
                    "domain": {
                        "id": "default"
                    },
                    "password": "$ABC123",
                    "name": "user@router"
                }
            },
            "methods": [
                "password"
            ]
        }
    }
}

Example:

alt
  1. Select the Headers tab in the response output and copy the 'X-Subject-Token' key value as shown in the output below.

  1. Click Save button to save the API with a specific name to reuse in the future.

    alt

  2. Once the token is generated, you can send various CSO HTTP Rest API requests (GET, POST, DELETE etc) as shown below:

    1. Send API request with valid URL, headers and method
      URL: https://CSO IP Address/namespace/object

      CSO IP Address => CSO VIP IP if CSO deployed in HA mode or CSO  baremetal server ip if CSO deployed in standalone mode
      namespace => microservice name
      object => name of object exposed under microservice http namespace

Method: GET/Delete/POST etc
Headers:

Accept = application/Json
X-AUTH-TOKEN = Paste the token value retrieved in Step 4

Example:

Related Information