Request Access Token

The third-party application must first request an access token, then include the access token in every request to access the Yeastar Partner Portal API.

Prerequisites

Enable API function on Yeastar Partner Portal, and obtain the API credentials (Client ID and Client Secret).

Request URL

POST {base_url}/auth/openapi/v1/oauth/token

Request parameters

Headers
Parameter Required Description
User-Agent Yes Provide information about the user agent, such as the type of web browser, operating system, software version, etc., so as to help Yeastar Partner Portal to identify the user or the application that is making the request.

Example: User-Agent: OpenAPI.

Content-Type Yes Specify the type of data that is sent in the body of a POST request.

Valid value: multipart/form-data or application/x-www-form-urlencoded.

Body parameters
Parameter Required Type Description
client_id Yes String Client ID.

You can obtain the Client ID on Yeastar Partner Portal.

client_secret Yes String Client secret.

You can obtain the Client Secret on Yeastar Partner Portal.

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

Valid value: pp_credentials.

Response parameters

Parameter Type Description
code String The response message of the API request.
detailMessage String The detailed error information.

When the request is successful, this parameter returns empty.

requestId String The unique ID of the request, which can be used to quickly locate the request.
result Object<Token_Details> Details of the requested tokens.
status Integer The HTTP status code of the API request.
Token_Details
Parameter Type Description
expiresIn String The remaining validity period of the access token (Unit: second).
refreshToken String Refresh token, which can be used to refresh an access token.
token String The authentication credential for API calls. All API requests must include an access token.
tokenHead String The prefix of the access token in the HTTP Authorization header. The value is fixed at Bearer.

Example

Request example

Request an access token with Client ID and Client Secret.

  • Example 1: Request using content type multipart/form-data

    POST /auth/openapi/v1/oauth/token HTTP/1.1
    Host: openapi.partner.yeastar.com
    User-Agent: OpenAPI
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
    
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="client_id"
    
    acxxxxxxxxxxxf3
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="client_secret"
    
    d3xxxxxxxxxxxee
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="grant_type"
    
    pp_credentials
    ------WebKitFormBoundary7MA4YWxkTrZu0gW--
    Figure 1. Request example in Postman

  • Example 2: Request using content type application/x-www-form-urlencoded

    POST /auth/openapi/v1/oauth/token HTTP/1.1
    Host: openapi.partner.yeastar.com
    User-Agent: OpenAPI
    Content-Type: application/x-www-form-urlencoded
    
    client_id=acxxxxxxxxxxxxxf3&client_secret=d3xxxxxxxxxxee&grant_type=pp_credentials
    Figure 2. Request example in Postman

Response example

{
    "code": "success",
    "detailMessage": "",
    "requestId": "dcba1ee8cce1f431341178aaff06db6f",
    "result": {
        "expiresIn": 1800,
        "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdLCJYLU1TLVVTRVIiOiJ7XCJleHByXCI6XCIwXCIsXCJ0eXBlXCI6XCJwYXJ0bmVyXCIsXCJ1Y0lkXCI6XCIzMDc2OTEzNjQ0ODkwODMyODk2XCIsXCJ1c2VyQ29kZVwiOlwiRGlzdHJpYnV0b3JcIixcInVzZXJJZFwiOlwiMzA3NjkxMzY0NDkxNTk5ODcyMFwiLFwidXNlcm5hbWVcIjpcImRpc3RyaWJ1dG9yZXhhbXBsZUBvdXRsb29rLmNvbVwifSIsInVzZXJfbmFtZSI6ImRpc3RyaWJ1dG9yZXhhbXBsZUBvdXRsb29rLmNvbSIsInNjb3BlIjpbImFsbCJdLCJhdGkiOiI3aWhRdlplVU85VU5XY2Mzem9XVXowVVFUTm89IiwiZXhwIjoxNzA5Nzg5MTk1LCJ0b2tlbl90eXBlIjoib3BlbmFwaSIsImF1dGhvcml0aWVzIjpbIjc3Il0sImp0aSI6IkJSUE85aUYwclplNHMrOGdURThveTh1TlVmTT0iLCJjbGllbnRfaWQiOiJhYzBmMmU1YmVlNzZiNmQ3ZjQ1NDU2OTZjMjRmYzFmMyJ9.pcn0Psd9s9LvMpM-kGA5rJ797XdMMxf0h6-K6UcPxc0",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdL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