Making an API Request
This section describes the structure of a REST API request and introduces how to call an API. For details, see Creating an IAM User.
Request URI
The format of a request URI is as follows:
{URI-scheme} :// {Endpoint} / {resource-path} ? {query-string}
Although a request URI is included in the request header, most programming languages and frameworks require the request URI to be transmitted separately.
- URI-scheme: Protocol used to transmit requests. All APIs use HTTPS.
- Hostname: Domain name or IP address of the server hosting the REST service endpoint. Obtain the value from Regions and Endpoints. For example, the hostname of IAM in the CN-Hong Kong region is iam.ap-southeast-1.myhuaweicloud.com.
- resource-path: access path of an API for performing a specific operation. Obtain the value from the URI of an API. For example, the resource-path of the API for Creating an IAM User is /v3.0/OS-USER/users.
- query-string: Query parameter, which is optional. A query parameter must be prefixed with a question mark (?), 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, if you want to create an IAM user, use the endpoint of any region (for example, CN-Hong Kong iam.ap-southeast-1.myhuaweicloud.com) because IAM is a global service. Then, find the resource-path (/v3.0/OS-USER/users) in the URI of the API for Creating an IAM User. The result is as follows:
https://iam.ap-southeast-1.myhuaweicloud.com/v3.0/OS-USER/users

In the URI of each API, only resource-path and the request method are provided. This is because the URI-scheme of all APIs is HTTPS and the hostnames of all APIs in the same region are identical.
Request Method
The HTTP protocol defines the following request methods that can be used to send a request to the server.
Request Method |
Description |
---|---|
GET |
Request the server to return specified resources. |
PUT |
Request the server to update specified resources. |
POST |
Request the server to add resources or perform special operations. |
DELETE |
Requests the server to delete a specified resource, for example, an object. |
HEAD |
Request the server resource header. |
PATCH |
Request the server to update partial content of a specified resource. If the requested resource does not exist, the server may create a resource using the PATCH method. |
For example, in the URI of the API for Creating an IAM User, the request method is POST and the request is as follows:
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3.0/OS-USER/users
Request Header
You can also add additional header fields to a request, such as the fields required by a specified URI or HTTP method. For example, add Content-Type that defines a request body type to request the authentication information.
The following common headers need to be added to the request:
Field |
Mandatory (Yes/No) |
Description |
---|---|---|
Content-Type |
Yes |
Request body type (format). The default value is application/json. Other values will be provided for specific APIs. |
Authorization |
No |
Signature authentication information. When AK/SK-based authentication is used, SDK will automatically fill in this field when signing the request. For details about Access Key ID (AK)/Secret Access Key (SK)-based authentication, see AK/SK-based Authentication. |
X-Sdk-Date |
No |
Time when a request is sent. When AK/SK-based authentication is used, SDK will automatically fill in this field when signing the request. For details about AK/SK-based authentication, see AK/SK-based Authentication. |
X-Auth-Token |
No |
User token. This field is mandatory for token authentication. It is the response value of the API for Obtaining a User Token. This API is the only one that does not require authentication. |
X-Project-ID |
No |
Subproject ID. This field is used in multi-project scenarios. If cloud service resources are created in a subproject, the request for calling the API to perform operations on the resources must contain the X-Project-ID header field when AK/SK-based authentication is used. |
X-Domain-ID |
No |
Account ID. In AK/SK-based authentication, the request for calling the API of a global service must contain the X-Domain-ID header field. |
The following shows a request for calling the API for Creating an IAM User when AK/SK-based authentication is used.
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3.0/OS-USER/users Content-Type: application/json X-Sdk-Date: 20240416T095341Z Authorization: SDK-HMAC-SHA256 Access=****************, SignedHeaders=content-type;host;x-sdk-date, Signature=****************
Request Body
The body of a request is often sent in a structured format as specified in the Content-Type header. The request body transfers content except the request header. If the request body contains Chinese characters, the Chinese characters must be encoded using UTF-8 and the encoding mode must be specified in Content-Type, for example, Content-Type: application/json; charset=utf-8.
The request body varies depending on APIs. Some APIs do not require a request body, such as the APIs requested using the GET or DELETE method.
The request body of the API for Creating an IAM User is as follows. You can find the required request parameters and parameter description in the API request. Set the parameters in bold based on the site requirements.
Field |
Description |
---|---|
accountid |
Account ID of the IAM user. |
username |
IAM username to be created |
|
Email address of the IAM user |
********** |
Login password of the IAM user |
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3.0/OS-USER/users Content-Type: application/json X-Sdk-Date: 20240416T095341Z Authorization: SDK-HMAC-SHA256 Access=****************, SignedHeaders=content-type;host;x-sdk-date, Signature=**************** { "user": { "domain_id": "accountid", "name": "username", "password": "**********", "email": "email", "description": "IAM User Description" } }
Till now, the content required by an API request is ready. You can send the request to call an API through curl, Postman, or coding.
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