Making an API Request
This section describes the structure of an API request, and uses the OneAccess API for login with a username and password as an example to demonstrate how to call an API. After successful request, the obtained session_token can then be used to obtain user information.
Prerequisites
Before calling APIs, obtain the ClientId 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}
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 log in with a username and password is /api/v2/sdk/login.
For example, to obtain a session_token for the domain name abcdefg.huaweioneaccess.com, provide this domain name and obtain the resource-path (/api/v2/sdk/login) in the URI of the API used to obtain a session_token. Then, construct the URI as follows:
https://abcdefg.huaweioneaccess.com/api/v2/sdk/login
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 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 log in with a username and password, the request method is POST. The request is as follows:
POST https://abcdefg.huaweioneaccess.com/api/v2/sdk/login
Request Header
You can also add additional fields to a request, such as the fields required by a specified URI or HTTP method. For example, fields that indicate user agent information and application ID.
Name |
Description |
Mandatory |
Example |
---|---|---|---|
X-operating-sys-version |
OS version of the caller. |
Yes |
Android 10 |
X-device-fingerprint |
Device fingerprint of the caller. |
Yes |
156aysdna213sc50 |
X-device-ip |
Caller IP address. |
No |
10.10.10.1 |
X-agent |
User agent information. |
Yes |
Mozilla/5.0 (Linux; Android 10; Redmi K30 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Mobile Safari/537.36 |
X-L |
Language type. |
No |
zh |
X-client-id |
Application ID, which is a ClientId allocated to an application after registration. |
Yes |
DRrYIqauawN0I8myTMoDTPys6ezGZxnm |
X-tenant-id |
Tenant ID. This parameter is mandatory for ISV applications. |
No |
08f770f51f80d2f40f38c00cb199fd20 |
X-signature |
Signature information, which is used to determine the user login status. This parameter is not required for all APIs. For details about how to construct the signature, see Signing a Session Token. |
No |
D0JeOUuVqU8Ixvl0xrmewQRk4AuGZrtk1RfBxueNKUrNPpgSbXrYnzw... |
An example request for calling the API used to log in with a username and password is as follows:
POST https://abcdefg.huaweioneaccess.com/api/v2/sdk/login X-operating-sys-version: Android 10 X-device-fingerprint: 156aysdna213sac X-device-ip: 10.10.10.1 X-agent: Mozilla/5.0 (Linux; Android 10; Redmi K30 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Mobile Safari/537.36 X-L: zh X-client-id: DRrYIqauawN0I8myTMoDTPys6ezGZxnm X-tenant-id: 08f770f51f80d2f40f38c00cb199fd21
(Optional) Request Body
The body of a request is often sent in a structured format (for example, JSON or XML) to transfer 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 log in with a username and password, 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 actual username and password, respectively.
POST https://abcdefg.huaweioneaccess.com/api/v2/sdk/login X-operating-sys-version: Android 10 X-device-fingerprint: 156aysdna213sac X-device-ip: 10.10.10.1 X-agent: Mozilla/5.0 (Linux; Android 10; Redmi K30 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.99 Mobile Safari/537.36 X-L: zh X-client-id: DRrYIqauawN0I8myTMoDTPys6ezGZxnm X-tenant-id: 08f770f51f80d2f40f38c00cb199fd21 { "user_name": "UserName", "password": "PassWord" }
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 log in with a username and password, session_token is the credential indicating successful login. This session_token can then be used to obtain user information.
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