Help Center> > Developer Guide >Preparation

Preparation

Introduction

This document describes how to call cloud service APIs through AK/SK authentication. It explains the signing process and implementation logic, and provides signature SDKs and invocation examples of different programming languages, such as Java, Go, Python, and C.

NOTE:
  1. The SDK of each programming language is packaged in the sample code and can be obtained separately. You can integrate the SDK into your application by referring to the API calling example.
  2. If no signing example of the programming language you use is provided, please sign requests by referring to AK/SK Authentication.
  3. Alternatively, APIs can be called by carrying a token. For details about the use of a token, see the API Reference of services with open APIs.
  4. AK/SK authentication supports API requests with a body not larger than 12 MB. For API requests with a larger body, token authentication is recommended.
  5. For the available APIs provided by each cloud service, see the API Reference.

Information Collection

Before constructing an API request, obtain the service endpoint, request URI, AK/SK, and project ID.

Table 1 Required information to be collected

Item

Description

Endpoint

Endpoint of a cloud service in a region.

For details, see Regions and Endpoints.

NOTE:

For all example request URLs in this document, the endpoint service.region.example.com is used as an example.

Project_Id

Project ID, which needs to be configured for the URI of most APIs to identify different projects.

For details on how to obtain the project ID, see Obtaining a Project ID.

AK/SK

Access key ID (AK) and secret access key (SK), which are used to sign API requests.

For details on how to obtain the AK/SK, see Obtaining an AK/SK.

URI

API request path and parameters.

Obtain the URI from the API Reference of the corresponding cloud service.

X-Domain-Id

Account ID, which is used for:

  • Obtaining a token for token authentication.
  • Invoking APIs of global services, such as Content Delivery Network (CDN), through AK/SK authentication.

For details on how to obtain the account ID, see Obtaining the Account Name and Account ID.

X-Project-Id

Sub-project ID, which is used in multi-project scenarios. If a cloud service resource is created in a sub-project, the sub-project ID must be included in requests sent to call the API for operating the resource.

For details on how to obtain the sub-project ID, see Obtaining a Project ID.

Obtaining a Project ID

A project ID is required in the URLs of some APIs when the APIs are called. It is also required when you obtain a token. Perform the following steps to obtain a project ID:

  1. Sign up and log in to the management console.
  2. Click the username in the upper right corner, choose My Credential from the drop-down list, and then view the project ID on the Projects tab page.
    Projects physically isolate cloud server resources by region, and multiple projects can be created in the same region to implement more fine-grained isolation. As shown in the following figure, find the region where your server resource locates, and obtain the corresponding project ID in the Project ID column.
    Figure 1 Viewing the project ID
    NOTE:

    To view the sub-project ID, click the project to expand the sub-project list.

Obtaining an AK/SK

If an AK/SK has already been generated, skip this step. Find the downloaded AK/SK file, which is usually named credentials.csv.

As shown in the following figure, the file contains the user name, access key ID, and secret access key.

Figure 2 Content of the credential.csv file
Perform the following procedure to generate an AK/SK:
  1. Sign up and log in to the management console.
  2. Click the username in the upper right corner and select My Credential from the drop-down list.
  1. Click the Access Keys tab.
  2. Click Add Access Key.
  3. Enter the password and SMS verification code, and click OK to download the access key. Keep the access key secure.
Figure 3 Obtaining an access key

Obtaining the Account Name and Account ID

Your account name and account ID need to be specified in the URLs of some APIs when the APIs are called. Perform the following steps to obtain your account name and account ID:

  1. Sign up and log in to the management console.
  2. Click the username and choose My Credential from the drop-down list.

    View the account name and account ID.

    Figure 4 Viewing the account name and account ID