Updated on 2022-09-23 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 or IAM 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.

Creating an App

  1. On the DataArts Studio console, locate an instance and click Access. On the displayed page, locate a workspace and click 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 1 Application details page

Authorizing an Application to Use an API

  1. On the DataArts Studio console, locate an instance and click Access. On the displayed page, locate a workspace and click 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 Calls > Service Catalogs.
    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

The only difference between the three authentication methods is the authentication content. The methods for calling APIs are the same.

  • IAM Authentication: IAM authenticates API requests.
  • Non-authentication: No authentication is required. You can directly call an API.
  • App Authentication: Application authentication is used for calling an API.
    • When App Authentication is used, an SDK is required for access.
    • Currently, Java, Go, Python, JavaScript, C#, PHP, C++, C, and Android SDKs are available.
    • For details on API calling examples in different programming languages, see Java, Go, Python, C#, JavaScript, PHP, C++, C, and Android.