Skip to Content

Call SAP HANA Cockpit GET APIs

Introduce all the available SAP HANA cockpit GET APIs and the method to use them.
You will learn
  • What are the cockpit GET APIs that you can use
  • How to call a cockpit GET APIs
Cynthia CuiJune 21, 2022
Created by
November 20, 2018
Contributors
amy2187
thecodester

Prerequisites

  • Install the Python programming language on the computer that will call the endpoints

SAP HANA cockpit provides non modifying (GET) REST API endpoints. The GET APIs don’t create, delete, or change anything in the cockpit - they only inform you the existing information that you would like to examine.

There are five cockpit GET API endpoints:

  1. RegisteredResourcesGet: returns information about the resources registered in SAP HANA cockpit
  2. GroupsForUserGet: returns information about the resource groups that are visible to you
  3. GroupResourcesGet: returns information about the resources in a specified group that is visible to you (uses cockpit-landscape-svc)
  4. GroupUsersGet: returns information about the cockpit users in SAP HANA cockpit Database Group
  5. CockpitUsersGet: returns information about cockpit users

Only two of the five cockpit GET APIs will be further explained in the following steps. To know more about the cockpit GET APIs, click here to navigate to the SAP Help Portal.

The sample code for all the cockpit APIs (GET and POST ones) is posted at the end of the cockpit POST APIs tutorial as an appendix. The code is written in Python and you are welcome to copy and run it to examine how each API works.

  • Step 1

    This endpoint provides information about the resources registered in SAP HANA cockpit that you are allowed to see.

    To use this API, copy the following code to your Python file.

    Python
    Copy
    def list_cockpit_resources(client, authorization):
        targetURI = baseURL + '/resource/RegisteredResourcesGet'
    
        resourceListResponse = client.get(targetURI, verify=False, headers=get_header(authorization))
        return resourceListResponse.json()
    

    Suppose we only want all the names and the ID numbers of the cockpit resources. We then need to parse the JSON response:

    Python
    Copy
    result = list_cockpit_resources(client, authorization)
    resources = result["result"]
    print("Cockpit resources:")
    for resource in resources:
        print("- Resource name: " + resource["ResourceName"] + ", resource ID: " + resource["ResourceId"])
    

    Run the entire program and your output should be similar to the following:

    Cockpit resources:
    - Resource name: SYSTEMDB@H4C, resource ID: 1
    - Resource name: SYSTEMDB@DB1, resource ID: 2
    - Resource name: DB1@DB1, resource ID: 3
    

    In the area below, copy the Python output of your cockpit resources, and then click Validate.

  • Step 2

    This endpoint returns information about the existing resource groups in SAP HANA cockpit that you are allowed to see. As mentioned in the previous tutorial Get Ready to Use the SAP HANA Cockpit REST API, you will need your port number for cockpit-landscape-svc to be able to call this endpoint.

    To use this endpoint, copy the following code to your Python source file. Replace <host.domain.com> and with your own identities.

    Python
    Copy
    def list_cockpit_groups(client, authorization):
        targetURI = 'https://' + '<host.domain.com>' + ':' + '<port for cockpit-landscape-svc>' + '/group/GroupsForUserGet'
    
        groupListResponse = client.get(targetURI, verify=False, headers=get_header(authorization))
        return groupListResponse.json()
    

    Suppose we only want all the names of the cockpit groups, we then need to parse the JSON response:

    Python
    Copy
    result = list_cockpit_groups(client, authorization)
    groups = result["result"]
    print("Cockpit groups:")
    for group in groups:
        print("- Group name: " + group["Name"])
    

    Run the entire program and your output should be similar to the following:

    Cockpit groups:
    - Group name: GROUP1
    - Group name: GROUP2
    - Group name: GROUP3
    

    In the area below, copy the Python output of your cockpit groups, and then click Validate.

Back to top