Making an API Request
This section describes the structure of a REST API request and use the API for obtaining a temporary security credential through an agency or trust agency as an example to describe how to call an API. By using the API, a temporary security credential is obtained through an agency or trust agency. The obtained security credential contains the user identity information and permissions and is used to sign the requests for other API calls.
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 the request URI to be transmitted separately.
- URI-scheme: Protocol used to transmit requests. All APIs use HTTPS.
- Endpoint: Domain name or IP address of the server running the REST service. The endpoint varies between services in different regions. It can be obtained from Regions and Endpoints. .
- resource-path: Access path of an API for performing a specified operation. It can be obtained from the URI of an API. For example, the resource-path of the API used to obtain a temporary security credential through an agency or trust agency is /v5/agencies/assume.
- query-string: Query parameter, which is optional for APIs. 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 a temporary security credential in the CN North-Beijing4 region, obtain the endpoint of IAM (sts.cn-north-4.myhuaweicloud.com) for this region and the resource-path (/v5/agencies/assume) in the URI of the API for obtaining a temporary security credential through an agency or trust agency. Then, construct the URI as follows:
https://sts.cn-north-4.myhuaweicloud.com/v5/agencies/assume

To simplify the URI display in this document, each API is provided only with a resource-path and a request method. 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:
- 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: requests the server to delete specified resources, for example, an object.
- HEAD: requests the server to return only the response header.
- PATCH: requests the server to update partial content of a specified resource. If the resource does not exist, a new resource will be created.
For example, in the URI of the API for obtaining a temporary security credential through an agency or trust agency, the request method is POST and the request is as follows:
POST https://sts.cn-north-4.myhuaweicloud.com/v5/agencies/assume
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, to request for the authentication information, add Content-Type, which specifies the request body type.
Common request header fields are as follows:
- Content-Type: specifies the request body type or format. This field is mandatory and its default value is application/json. Other values of this field will be provided for specific APIs if any.
- Authorization: requests signature information. This field is mandatory. You can use a permanent AK/SK pair or temporary security credential to sign requests based on AK/SK-based Authentication.
APIs support AK/SK authentication, which uses SDKs to sign a request. During the signature, the Authorization (signature information) and X-Sdk-Date (time when the request is sent) headers are automatically added in the request.
For more information, see AK/SK-based Authentication.
- X-Project-ID: subproject ID. This field is optional and can be used in multi-project scenarios.
- X-Domain-ID: account ID (equivalent to AccountId).
For the API used to obtain a temporary security credential through an agency or trust agency, an example of such requests is as follows:
POST https://sts.cn-north-4.myhuaweicloud.com/v5/agencies/assume Content-Type: application/json x-sdk-date: 20191115T033655Z Authorization: SDK-HMAC-SHA256 Access=QTWAOYTTINDUT2QVKYUC, SignedHeaders=content-type;host;x-sdk-date, Signature=7be6668032f70418fcc22abc52071e57aff61b84a1d2381bb430d6870f4f6ebe
Request Body
The body of a request is often sent in a structured format as specified in the Content-Type header field. The request body transfers content except the request header. If the request body contains Chinese characters, these characters must be encoded in UTF-8.
For details about the message body of each API, see the API definition. Not all requests require a message body. For example, some GET and DELETE operations do not require a message body.
For the API used to obtain a temporary security credential through an agency or trust agency, you can obtain the request parameters and parameter descriptions from the API request. The following provides an example request with a body included. Replace agency_urn and agency_session_name with the actual values.
The duration_seconds parameter specifies the validity period of a security credential. The security credential obtained in the following example is valid only for one hour. You can further define the permissions of security credentials. For details, see Obtaining a Temporary Security Credential Through an Agency or Trust Agency.
POST https://sts.cn-north-4.myhuaweicloud.com/v5/agencies/assume
Content-Type: application/json
x-sdk-date: xxxxxxxxxxxxxxxxxx
Authorization: ********
{
"duration_seconds": "3600"
"agency_urn": "agency_urn",
"agency_session_name": "agency_session_name",
}
If all data required for the API request is available, you can send the request to call the API through curl, Postman, or coding. In the response header for the API used to obtain a temporary security credential through an agency or trust agency, credentials is the desired temporary security credential. This temporary security credential can then be used to call other APIs through AK/SK-based authentication.
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