Making an API Request
This section describes the structure of a REST API, and uses the ESM API for creating a query task as an example to describe how to call an API.
Request URI
A request URI is in the following format:
{URI-scheme}://{Endpoint}/{resource-path}?{query-string}
Although a request URI is included in the request header, most programming languages or frameworks require passing the request URI separately.
Parameter |
Description |
---|---|
URI-scheme |
Protocol used to transmit requests. All APIs use HTTPS. |
Endpoint |
Domain name or IP address of the server where the REST service is deployed. The value varies depending on services and regions. Obtain the value of this parameter from Regions and Endpoints. For example, the endpoint of ESM in the CN South-Guangzhou region is esm-api.cn-south-1.myhuaweicloud.com. |
resource-path |
Access path of an API. Obtain the path from the URI of an API. For example, resource-path of the API for creating a query task is /meter/v1/{domain_id}/query-jobs. |
query-string |
(Optional) Query parameter. Not all APIs have a query parameter. Ensure that a question mark (?) is included before each query parameter that is in the format of "Parameter name=Parameter value". For example, ?limit=10 indicates that a maximum of 10 data records will be displayed. |
For example, to obtain an ESM token in the CN South-Guangzhou region, obtain the ESM endpoint (esm-api.cn-south-1.myhuaweicloud.com) for this region and the resource-path (/meter/v1/{domain_id}/query-jobs) in the URI of the API used to create a query task. Then, construct the URI as follows:
https://esm-api.cn-south-1.myhuaweicloud.com/meter/v1/{domain_id}/query-jobs


To simplify the URI display, this document provides only the resource-path and request method in the URI of each API. The URI-scheme of all APIs is HTTPS, and the endpoints of all APIs in the same region are identical.
Request Methods
The HTTP protocol defines the following request methods that can be used to send a request to the server.
Method |
Description |
---|---|
GET |
Requests a server to return specified resources. |
PUT |
Requests the server to update specified resources. |
POST |
Requests the server to add resources or perform special operations. |
DELETE |
Request the server to delete specified resources, for example, an object. |
For example, in the URI of the API used to create a query task, the request method is POST. The request is as follows:
POST https://esm-api.cn-south-1.myhuaweicloud.com/meter/v1/{domain_id}/query-jobs
Request Headers
You can add additional header fields to a request, such as the fields required by a specified URI or HTTP method. For example, add Content-Type, which specifies the request body type, to a request for the authentication information.
Table 3 lists common request header fields.
Name |
Description |
Mandatory |
Example Value |
---|---|---|---|
Content-Type |
Type (or format) of requests being sent from a client to a server. The default value application/json is recommended. Other values will be described in specific APIs. |
Yes |
application/json |
Accept |
Type (or format) of the response content a client is expecting. Currently, the value can only be application/json. |
No |
application/json |
X-Auth-Token |
User token. The user token is a response to the API used to obtain a user token. This API is the only one that does not require authentication. After the request is processed, the value of X-Subject-Token in the response header is the token value. |
Yes This field is mandatory for authentication using tokens. |
The following is part of an example token: MIIPAgYJKoZIhvcNAQcCo...ggg1BBIINPXsidG9rZ |
(Optional) Request Body
This part is optional. A request body is generally sent in a structured format (for example, JSON or XML), which is specified by Content-Type in the request header. It is used to transfer content other than the request header. If the request body contains full-width characters, these characters must be coded in UTF-8.
Request bodies vary depending on APIs. Some APIs do not require a request body, such as the APIs requested using the GET and DELETE methods.

In the case of the API used to create a query task, you can obtain the required request parameters and parameter descriptions from the API request. The following is a request carrying the message body, where the values of the fields are examples:
POST https://esm-api.cn-south-1.myhuaweicloud.com/meter/v1/{domain_id}/query-jobs Content-Type: application/json { "hcso_id": "********", "region_id": "********", "min_sdr_time": "2022-01-01 00:00:00", "max_sdr_time": "2022-02-01 00:00:00" }
If all data required for the API request is available, you can send the request to call an API through curl, Postman, or coding. In the response to the API used to obtain a user token, x-subject-token is the target user token. This token can then be used to authenticate other API calls.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot