Skip to main content

API Authorization

This authorization method is for team developers to read and write team data.

Step 1: Obtain Team Authorization access_token

Important Notes!

  1. The access_token obtained here is related to team resources and has a very high security level. It must be stored only on the server and cannot be passed to the client.
  2. Subsequent steps using the access_token to obtain team data must also be initiated from the server.
  3. It is recommended that developers use a central control server to uniformly obtain and refresh access_tokens. Other business logic servers should use access_tokens from this central control server and should not refresh them individually, as this can easily cause conflicts and affect business operations (when refreshing access_token multiple times, only the latest one is valid).
  4. The access_token is valid for 2 hours. The central control server should not only actively refresh internally on a schedule but also provide a passive refresh interface for access_tokens. This allows business servers to trigger the access_token refresh process when an API call indicates that the access_token has expired.

API Endpoint

GET https://open.wesurvey.com/api/oauth2/access_token?appid={appid}&secret={secret}&grant_type=client_credential

Replace {appid} and {secret} with the application credentials obtained from the team management page. Do not include the brackets {} when making the request.

Parameter Description

Parameter NameTypeRequiredDescription
appidstringYesApplication ID issued to the team
secretstringYesApplication secret issued to the team
grant_typestringYesFixed value: client_credential

Response Description

Parameter NameTypeDescription
access_tokenstringAuthorization code
expires_inintegerValid duration, default is 2 hours, must re-authorize after expiration
{
"code": "OK",
"error": {
"type": ""
},
"data": {
"access_token": "ACCESS_TOKEN",
"expires_in": 7200
},
"request_id": "6cda53f4-d0fa-41a9-95a0-77ea32c97f1e"
}

Error Codes

error.type CodeDescription
request_rate_limitedRequest frequency is too high. Please reduce the frequency. access_token is valid for 2 hours and should be cached rather than obtained in real-time
invalid_org_subscriptionThe current team version does not have permission to use the API. Please upgrade first

Step 2: Use access_token to Request Team Survey Data

Add ?appid={APPID}&access_token={ACCESS_TOKEN} to the API request
For example, to get team survey details:

GET https://open.wesurvey.com/api/surveys/{survey_id}/legacy?appid={APPID}&access_token={ACCESS_TOKEN}

Some APIs require ?openid={OPENID} For example, to get a user's survey list:

GET https://open.wesurvey.com/api/surveys?appid={APPID}&access_token={ACCESS_TOKEN}&openid={OPENID}