Support Support Downloads Knowledge Base Juniper Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

Example: How to execute CSO HTTP Restful APIs using Postman API Client

0

0

Article ID: KB36597 KB Last Updated: 19 Nov 2021Version: 2.0
Summary:

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 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.
    • Get the token using curl commands in CLI. Refer to KB34116.
    • 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:

  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.

  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 Links

Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search