Making an API Request
This section describes the structure of an API request, and uses the OneAccess management API for obtaining an access credential as an example to demonstrate how to call an API. The obtained access credential can then be used to call other management APIs.
Prerequisites
Before calling APIs, ensure that your administrator has authorized them by referring to Authorizing APIs, and obtain ClientId and ClientSecret of added applications in the administrator portal from Basic Information.
Request URI
A request URI is in the following format:
{URI-scheme} :// {domain_name} / {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.
- domain_name: User access domain name that you must specify when you call a OneAccess API. For details about how to obtain the domain name, see Obtaining the User Access Domain Name.
- resource-path: Access path of an API for performing a specified operation. Obtain the path from the URI of an API. For example, the resource-path of the API used to obtain an access credential is /api/v2/tenant/token.
- query-string: An optional 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 access credential for the domain name abcdefg.huaweioneaccess.com, provide this domain name and obtain the resource-path (/api/v2/tenant/token) in the URI of the API used to obtain an access credential. Then, construct the URI as follows:
https://abcdefg.huaweioneaccess.com/api/v2/tenant/token
To simplify the URI display, each API is provided only with a resource-path and a request method. The URI-scheme of all APIs is HTTPS, and the domain_name values of all APIs in the same instance 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 the response header only.
- 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 case of the API used to obtain an access credential, the request method is POST. The request is as follows:
POST https://abcdefg.huaweioneaccess.com/api/v2/tenant/token
Request Header
Name |
Description |
Mandatory |
Example |
---|---|---|---|
Content-Type |
Specifies the request body type or format. The default value is application/json. Other values of this field will be provided for specific APIs if any. |
Yes |
application/json |
Accept |
Response type. The default value application/json is recommended. Other values of this field will be provided for specific APIs if any. |
No |
application/json |
Content-Length |
Length of the request body, in bytes. |
No |
3495 |
Authorization |
Authentication credential. For example, you can set this field to Bearer {access_token} when you call the API used to query user information. |
No |
Bearer {access_token} |
The API used to obtain an access credential does not require authentication. Therefore, only the Content-Type field needs to be added to requests for calling the API. An example of such requests is as follows:
POST https://{domain_name}/api/v2/tenant/token Content-Type: application/x-www-form-urlencoded
(Optional) Request Body
This part is optional. The body of a request is often sent in a structured format (for example, JSON or XML) as specified in the Content-Type header field. The request body transfers content except the request header.
The request body varies between APIs. Some APIs do not require the request body, such as the APIs requested using the GET and DELETE methods.
In the case of the API used to obtain an access credential, the request parameters and parameter description can be obtained from the API request. The following provides an example request with a body included. Replace UserName and Password with the API credential ID and secret assigned after application registration.
POST https://{domain_name}/api/v2/tenant/token?grant_type=client_credentials
Content-Type: application/x-www-form-urlencoded
Authorization: Basic eFFp******************************************************************************************************bzZaNg==
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 to the API used to obtain an access credential, Authorization is the desired access credential. This access credential can then be used to authenticate the calling of other APIs.
This is a Postman calling example.
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