Get an Access Token

Access token is used to verify an authenticated API call. Applications must first request an access token, then include the it in every request to access the Milesight Development Platform API.

Prerequisites

You have created an Application on Milesight Development Platform and obtained the following items:
  • Server Address
  • Client ID
  • Client Secret

Request URL

POST {base_url}/oauth/token

Request Parameters

Table 1. Body parameters
Parameter Required Type Description
client_id Yes String The Client ID obtained from the Application you created on Milesight Development Platform.
client_secret Yes String

The Client Secret obtained from the Application you created on Milesight Development Platform.

grant_type Yes String The OAuth grant type for requesting an access token.

Valid value: client_credentials

Response Parameters

Parameter Type Description
data Object<Token_Details> Details of the requested tokens.
status String The result of the API request.
  • Success
  • Failed
requestId String The unique ID of the request, which can be used to quickly locate the request.
Token_Details
Parameter Type Description
access_token String The authentication credential for API calls. All API requests must include an access token.
Note: If the access token is compromised, you can regenerate the Client Secret on Milesight Development Platform and request a new one, and the previous one will be invalidated automatically.
refresh_token String Refresh token, which can be used to refresh an access token.
expires_in Integer The remaining validity period of the access token (Unit: second).
refresh_token_expires_in Integer The remaining validity period of the refresh token (Unit: second).

Examples

Request example

Request an access token with Client ID and Client Secret.

POST /oauth/token HTTP/1.1
Host: demo.milesight.com
Content-Type: x-www-form-urlencoded

client_id=ee6ad650-7d33-414d-bafb-xxxxxxxxxxxx&client_secret=zy6ClNXcTkzTtfPB1tswxxxxxxxxxxxx&grant_type=client_credentials
Response example
HTTP/1.1 200 OK
{
    "data": {
        "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InllYXN0b25lLWRlZmF1bHQta2V5LWlkIn0.eyJncmFudF90eXBlIjoiY2xpZW50X2NyZWRlbnRpYWxzIiwic2NvcGUiOlsib3BlbmFwaSJdLCJjbGllbnRfZXh0Ijp7ImFwcF9pZCI6IjE3MzQ0NzUwODY0NjY2MDA5NjIifSwiZXhwIjoxNzAyNDU1MDM1LCJhdXRob3JpdGllcyI6WyJST0xFX0NMSUVOVCJdLCJqdGkiOiJlYTRiZjYyMS1kMTFiLTRiNmItYTQ5Yi00YWZmODA2ODM4NDAiLCJjbGllbnRfaWQiOiJlZTZhZDY1MC03ZDMzLTQxNGQtYmFmYi0wODM3YjNlMzQzMWQiLCJ0cyI6MTcwMjQ1MTQzNTMzN30.CY_fgSs_Ew7HYF1QgBFOHgJf_YyWo59xbz4iPCCK9zpzqoSX4mRcOo0SpYSk2IkupiZYfw2ZtXb6XNhYLN--wXXuikxWtbxGj4LSO4baUDlzIAZ03dJzZX0nX12b3bmgNtKi6qxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InllYXN0b25lLWRlZmF1bHQta2V5LWlkIn0.eyJncmFudF90eXBlIjoiY2xpZW50X2NyZWRlbnRpYWxzIiwic2NvcGUiOlsib3BlbmFwaSJdLCJjbGllbnRfZXh0Ijp7ImFwcF9pZCI6IjE3MzQ0NzUwODY0NjY2MDA5NjIifSwiYXRpIjoiZWE0YmY2MjEtZDExYi00YjZiLWE0OWItNGFmZjgwNjgzODQwIiwiZXhwIjoxNzA1MDQzNDM1LCJhdXRob3JpdGllcyI6WyJST0xFX0NMSUVOVCJdLCJqdGkiOiI4MGRkZDMzMy0wZGVlLTQwYzMtODU3Ny0xNzViOTJlMzIwZDUiLCJjbGllbnRfaWQiOiJlZTZhZDY1MC03ZDMzLTQxNGQtYmFmYi0wODM3YjNlMzQzMWQiLCJ0cyI6MTcwMjQ1MTQzNTMzN30.YN-JqX9RDxAfTElL2ftojqWhJCNyYdtgezRKpFMTUp0H7mtN-07kCL1Ue72vG58gfPh_C87V6joCJsR7_WfpUvQX6kn4jpLRM3JDT0A8D8lk5w5Mul6lBd6bHEtXNxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "expires_in": 3599,
        "refresh_token_expires_in": 2591999
    },
    "status": "Success",
    "requestId": "72fea33ad6f721a3a218cc6f60c5fff1"
}