Updated on 2023-09-27 GMT+08:00

Calling APIs

Overview

To call an API, perform the following operations:
  1. Obtain an API.

    Obtain the API from the service catalog. An API can be called only after it is published.

  2. (Optional) Create an application and get authorized.

    For an API that is accessed using application authentication, you need to create an application and authorize the application to use the API. When you call an API, DataArts DataService verifies your identity based on the key pair (AppKey and AppSecret) of the created application.

  3. Call the API.

    After completing the preceding steps, you can call the API.

(Optional) Creating an App

Perform this operation when the API to be called uses app authentication.

  1. On the DataArts Studio console, locate an instance and click Access. On the displayed page, locate a workspace and click DataArts DataService.
    Figure 1 DataArts DataService

  1. In the left navigation pane, choose an edition, for example, Exclusive Edition. The Overview page is displayed.
  2. Choose API Calling > Apps. On the page displayed, click Create. The Create App dialog box is displayed. Set the parameters listed in Table 1.
    Table 1 App information

    Parameter

    Description

    Name

    The name of the application to create.

    Type

    IAM: IAM authentication is used, which means access using a token.

    APP: access through app authentication

    Description

    A description of the application to create.

  3. Click OK.

    After the application is created, its name and ID are displayed in the application list.

  4. Click an application name, and view the AppKey and AppSecret on the displayed application details page.
    Figure 2 Application details page

(Optional) Authorizing an App to Use an API

Perform this operation when the API to be called uses app authentication.

  1. On the DataArts Studio console, locate an instance and click Access. On the displayed page, locate a workspace and click DataArts DataService.
    Figure 3 DataArts DataService

  1. In the left navigation pane, choose an edition, for example, Exclusive Edition. The Overview page is displayed.
  2. Authorize an application to use an API in either of the following ways:
    Giving API authorization:
    1. Choose API Development > APIs.
    2. Locate the row that contains the API to be bound, and click View.

      On the page displayed, click Authorize.

    3. (Optional) If Parameter Location was set to Static for an input parameter during API creation, you must set a static parameter value. If you do not set a value, the default value of the API input parameter is used.
    4. Set an expiry time, select an application, and click OK.

    Applying for authorization:

    1. Choose API Calling > Service Catalogs to view all the published APIs.
    2. Click the name of the API you want to bind to an application.
    3. On the page displayed, click Permission Application.
    4. (Optional) If Parameter Location was set to Static for an input parameter during API creation, you must set a static parameter value. If you do not set a value, the default value of the API input parameter is used.
    5. Set an expiry time, select an application, and click OK.
    6. After the application is submitted, the authorization takes effect only after it is approved in the review center.
  3. After the authorization is complete, view the bound APIs on the application details page.
    • In the API list, if you no longer access an API through the application, click Unbind in the Operation column.
    • To test an API to which the application is bound, choose More > Debug in the Operation column
    • To extend the authorization period for the bound API, click Renew.

Calling an API

When creating an API, you can select one of the following authentication modes. The three modes differ in how the API is called. You are advised to use App Authentication, which is more secure that the other two modes.
  • App authentication: App authentication is used for calling an API. The AppKey & AppSecret is used for authentication. It is highly secure.

    When App authentication is used, an SDK is required for access. Java, Go, Python, JavaScript, C#, PHP, C++, C, and Android SDKs are available. For details about how to call APIs in each language, see Calling APIs Through App Authentication.

  • IAM authentication: IAM authenticates API requests. This mode is available only for Huawei cloud users. The security level is medium.

    When using IAM authentication, you need to call the Obtaining a User Token API of IAM to obtain a token, add the X-Auth-Token parameter with the obtained token as the value to the request header, and use an API calling tool or SDK to call released APIs.

  • Non-authentication: No authentication is required. This mode allows all users to access APIs, which may pose security risks. It is recommended only for testing APIs. If the caller is not a trusted user, there is a risk of data leakage, breakdowns caused by high concurrent access, SQL injection, and others.

    This mode does not require any authentication information. You can use an API calling tool or SDK to directly call an API by specifying required parameters.