Use an OpenAPI example

Updated at:

This topic describes how to use OpenAPI to manage SASE.

View the OpenAPI documentation

Go to API Reference to view the list of supported API operations. This topic uses the ListPrivateAccessTags operation to demonstrate how to use an OpenAPI SDK example.

Create a RAM user and grant permissions

Identity

You can call this API operation using an Alibaba Cloud account (root account), a RAM user, or a RAM role. For more information about the differences between these identities, see Identities, credentials, and authorization. In this example, a RAM user is used to call the API operation.

Log on to Resource Access Management (RAM), create a RAM user with API-only access, and record the AccessKey information. For more information, see Create a RAM user.

Grant permissions

  1. Go to the RAM user list. In the Actions column of the target RAM user, click Add Permissions.

  2. In the Permission Policy section, enter the keyword CSAS to search for the policy and select the AliyunCSASFullAccess policy.

    Note
    • The system permission policies for SASE are as follows:

      • AliyunCSASFullAccess: Grants full permissions to manage SASE.

      • AliyunCSASReadOnlyAccess: Grants read-only permissions to manage SASE.

    • To learn how to create a custom permission policy, see Authorization information.

  3. Click OK to complete the authorization.

Credentials

An AccessKey pair is automatically generated when you create a RAM user. You can use this AccessKey pair directly. Alternatively, on the RAM user's details page, click the User Security tab, and then click Create AccessKey. For more information, see Create an AccessKey pair.

Call an OpenAPI operation

This section shows how to call an OpenAPI operation by using Python.

Prepare the Python environment

  1. Download and install Python.

    You can download Python 3 from Python 3.

  2. Check your Python version.

    • Linux and macOS

      Open a terminal and run the python --version command.

    • Windows

      • In the Python installation directory, double-click python.exe.

      • Open Command Prompt.

        Press Win+R to open the Run dialog box, enter python, and then click OK.

Configure environment variables

For information about how to configure environment variables, see Configure environment variables on Linux, macOS, and Windows.

Install dependencies

pip install alibabacloud_credentials
pip install alibabacloud_csas20230120==1.0.1
pip install alibabacloud_tea_console

Download the example code

  1. In OpenAPI Portal, go to the API Debugger for the ListPrivateAccessTags operation.

  2. On the Parameters tab, enter values for the required parameters CurrentPage and PageSize, and then click Send Request.

  3. On the SDK Example tab, click the Python tab to view the SDK example.

  4. Click Download Project to download the code package.

  5. Decompress the downloaded package and go to the alibabacloud_sample directory.

Run the code

Run the following command:

python sample.py

The output is similar to the following:

{
	"headers": {
		"date": "Fri, 11 Aug 2023 03:36:37 GMT",
		"content-type": "application/json;charset=utf-8",
		"content-length": "372",
		"connection": "keep-alive",
		"keep-alive": "timeout=25",
		"access-control-allow-origin": "*",
		"access-control-expose-headers": "*",
		"x-acs-request-id": "E556521A-CC49-506D-8FB3-753CA5AE****",
		"x-acs-trace-id": "92cce71cf7f21e142c86d7fbb46d****",
		"etag": "3Eqai375bf2r78EqTr+R****"
	},
	"statusCode": 200,
	"body": {
		"RequestId": "E556521A-CC49-506D-8FB3-753CA5AED661",
		"Tags": [{
			"ApplicationIds": ["pa-application-58a9942ea689****", "pa-application-91f960671233****", "pa-application-c2ed1730f5f9****", "pa-application-e3f8d2c00703****"],
			"CreateTime": "2021-01-12 17:53:54",
			"Description": "",
			"Name": "Business systems",
			"PolicyIds": [],
			"TagId": "tag-3d3c384d002d****",
			"TagType": "Default"
		}],
		"TotalNum": 18
	}
}