OAuth Tokens
You can use the API to list existing OAuth access tokens for the Zendesk Chat API, or to revoke them.
JSON format
OAuth Tokens are represented as JSON objects with the following properties:
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
access_token | string | true | false | The access token |
agent_id | integer | true | false | The ID of the user this token authenticates as |
client_identifier | string | true | false | The ID of the client this token belongs to |
create_date | string | true | false | The time the token was created |
expire_date | string | true | false | The refresh token, if generated |
id | integer | true | false | The ID of the token. Automatically assigned when created |
refresh_token | string | true | false | The refresh token, if generated |
scopes | string | true | false | One or more allowed scopes for the client. Can be "read", "write", and "chat". SeeOAuth Authentication |
token_type | string | true | false | Token type. Must be "Bearer" |
Example
{
"access_token":"L0m2pVzxYpiVZOnzuWfGTHJjUxMicmbsEeGh4QSBqTTaScnprJNC8DusW5RwFTuo",
"agent_id":100000204,
"client_identifier":"zopim",
"create_date":"2014-09-09T07:49:20Z",
"expire_date":"2014-09-09T17:49:20Z",
"id":38,
"refresh_token":"pLZYNfA082RVrUt6ArGiKroVrN6CS9ZJ2glbty5rA1CejmSVlGPk5GjfKarDR5VS",
"scopes":"read write",
"token_type":"Bearer"
}
List OAuth Tokens
GET /api/v2/oauth/tokens
Lists all tokens under an agent.
Allowed for
- Administrator
代码示例
旋度
旋度https://www.zopim.com/api/v2/oauth/tokens\
-v -u{email_address}:{password}
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/oauth/tokens"
method:="GET"
req,err:=http.NewRequest(method,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/oauth/tokens")
.newBuilder();
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.method("GET",null)
.addHeader("Content-Type","application/json")
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
varaxios=require('axios');
varconfig={
method:'GET',
url:'https://support.zendesk.com/api/v2/oauth/tokens',
headers:{
'Content-Type':'application/json',
},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.catch(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/oauth/tokens"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"GET",
url,
headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/oauth/tokens")
request=Net::HTTP::Get.new(uri,"Content-Type":"application/json")
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
[
{
"access_token":"L0m2pVzxYpiVZOnzuWfGTHJjUxMicmbsEeGh4QSBqTTaScnprJNC8DusW5RwFTuo",
"agent_id":100000204,
"client_identifier":"zopim",
"create_date":"2014-09-09T07:49:20Z",
"expire_date":"2014-09-09T17:49:20Z",
"id":38,
"refresh_token":"pLZYNfA082RVrUt6ArGiKroVrN6CS9ZJ2glbty5rA1CejmSVlGPk5GjfKarDR5VS",
"scopes":"read write",
"token_type":"Bearer"
},
{
"access_token":"L0m2pVz124sdsGTHJjUxMicmbsEeGh4QSBqTTaScnprJNC8DusW5RwFTuo",
"agent_id":10000026,
"client_identifier":"zendesk",
"create_date":"2014-09-09T07:49:20Z",
"expire_date":"2014-09-09T17:49:20Z",
"id":143,
"refresh_token":"pLZYNfA082RV34sdsroVrN6CS9ZJ2glbty5rA1CejmSVlGPk5GjfKarDR5VS",
"scopes":"read write",
"token_type":"Bearer"
}
]
删除OAuth Token
DELETE /api/v2/oauth/tokens/{oauth_token_id}
Revokes the specified token.
Allowed for
- Administrator
Parameters
Name | Type | In | Required | Description |
---|---|---|---|---|
oauth_token_id | integer | Path | true | The ID of the OAuth Token |
代码示例
旋度
旋度https://www.zopim.com/api/v2/oauth/tokens/{id}\
-v -u{email_address}:{password}-X DELETE
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/oauth/tokens/1"
method:="DELETE"
req,err:=http.NewRequest(method,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/oauth/tokens/1")
.newBuilder();
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.method("DELETE",null)
.addHeader("Content-Type","application/json")
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
varaxios=require('axios');
varconfig={
method:'DELETE',
url:'https://support.zendesk.com/api/v2/oauth/tokens/1',
headers:{
'Content-Type':'application/json',
},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.catch(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/oauth/tokens/1"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"DELETE",
url,
headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/oauth/tokens/1")
request=Net::HTTP::删除.new(uri,"Content-Type":"application/json")
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
204 No Content
// Status 204 No Content
null