Updated on 2024-10-18 GMT+08:00

Calling APIs

You can call APIs opened by others in APIG.

Usage Guidelines

An API can be accessed 1,000 times by using the debugging domain name allocated when the API's group is created.

Obtaining API Calling Information

Obtain API calling information from the API provider before you call an API.

  • Request

    On the APIG console, choose API Publishing > APIs. Click an API name to view the domain name, request method, request path, and basic information of the API.

  • API authentication

    Obtain the request authentication information according to the API's authentication mode.

    Authentication Mode

    Authentication Information

    App (signature)

    Obtain the AppKey and AppSecret of the app authorized for the API from the API provider, as well as the signing SDK.

    App (simple authentication)

    Obtain the AppCode of the app authorized for the API from the API provider.

    IAM (token)

    Obtain the username and password for the cloud platform.

    IAM (AK/SK)

    Obtain the AK/SK of an account for the cloud platform and the signing SDK.

    Custom

    Obtain the custom authentication information to carry in request parameters from the API provider.

    None

    No authentication information required.

    • AppKey and AppSecret of the app

      On the shared gateway console, choose API Calling > Apps. In the app list, click the name of the app that the API is authorized to access. On the app details page that is displayed, obtain the AppKey and AppSecret of the app.

    • SDK used for authentication signatures

      On the shared gateway console, choose Help Center > SDK Process Flow, and download the SDK of the desired language.

    • AppCode

      On the shared gateway console, choose API Calling > Apps. In the app list, click the name of the app that the API is authorized to access. On the app details page that is displayed, obtain the AppCode on the AppCodes tab page.

Calling APIs

This section describes only the configuration of the request path and authentication parameters. For other parameters, such as timeout and SSL, configure them as required. To avoid service loss due to incorrect parameters, configure them by referring to the industry standards.

  1. Construct an API request. Example:
    POST https://{Address}/{Path}?{Query}
    {Header}
    
    {
      {Body}
    }
    • POST: request method. Replace it with the request method obtained in Obtaining API Calling Information.
    • {Address}: request address. Replace it with the domain name obtained in Obtaining API Calling Information.

      Scenario

      Request Parameter Configuration

      Calling an API with a domain name

      Call an API using the debugging domain name allocated to the API group or a domain name bound to the group. No additional configuration is required.

      Calling an API with an IP address

      To use an IP address to call an API, add the header parameter host.

    • {Path}: request path. Replace it with the request path obtained in Obtaining API Calling Information.
    • {Query}: (optional) query string in format "Parameter_name=Parameter_value", for example, limit=10. Separate multiple query strings with ampersands (&). For details, see the request parameters obtained in Obtaining API Calling Information.
    • {Header}: request header parameter in format "Parameter_name:Parameter_value", for example, Content-Type:application/json. For details, see the request parameters obtained in Obtaining API Calling Information.
    • {Body}: request body in JSON format. For details, see the request body description obtained in Obtaining API Calling Information.
  1. Add authentication information to the API request.

    Authentication Mode

    Request Parameter Configuration

    App (signature)

    Use the obtained SDK to sign the API request. For details, see Calling APIs Through App Authentication.

    App (simple authentication)

    Add the header parameter X-Apig-AppCode and set the parameter value to the AppCode obtained in Obtaining API Calling Information. For details, see Getting Started.

    IAM (token)

    Obtain a token from the cloud platform and add the header parameter X-Auth-Token with the token as the value. For details, see Token Authentication.

    IAM (AK/SK)

    Use the obtained SDK to sign the API request. For details, see AK/SK Authentication.

    Custom

    Add the information required for custom authentication to the API request.

    None

    Call APIs without authentication.