Making an API Request
This section describes the structure of a REST API request, 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 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, the resource-path of the API for creating a query task is /meter/v1/{domain_id}/query-jobs. |
query-string |
(Optional) Query parameter. It is not necessary to configure query parameters for all APIs. Ensure that there is a question mark (?) before each query parameter, in the format of "Parameter name=Parameter value". For example, ?limit=10 indicates that a maximum of 10 data records will be displayed. |
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 the 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, to request for the authentication information, add Content-Type, which specifies the request body type.
Table 3 lists common request header fields.
Name |
Description |
Mandatory |
Example |
---|---|---|---|
Content-Type |
Type (or format) of the request body 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 |
Method of receiving the response body. Currently, the value can only be application/json. |
No |
application/json |
X-Auth-Token |
User token. It is a response to the API for obtaining a user token. This API is the only one that does not require authentication. After a response is returned, 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 that need to be requested using GET and DELETE methods.

For the API used to create a query task, you can obtain the required request parameters and parameter description from the API request. The following is a request carrying a request body, where values of 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 a 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