Triggers
You can use the API to get or set the Trigger information.
JSON format
Triggers are represented as JSON objects with the following properties:
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
description | string | false | false | The description of the trigger |
enabled | integer | false | false | Whether the trigger is enabled or not |
id | integer | true | false | The ID of the trigger |
name | string | false | false | The name of the trigger |
Example
{
"description": "Visitor entered page",
"enabled": 1,
"id": 4,
"name": "Good Trigger"
}
List Triggers
GET /api/v2/chat/triggers
Lists triggers for an account.
Allowed for
- Administrator
Code Samples
curl
curl https://{subdomain}.zendesk.com/api/v2/chat/triggers \
-v -H "Authorization: Bearer {token}"
Go
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://subdomain.zendesk.com/api/v2/chat/triggers"
method := "GET"
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client {}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
import com.squareup.okhttp.*;
OkHttpClient client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://subdomain.zendesk.com/api/v2/chat/triggers")
.newBuilder();
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("GET", null)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Nodejs
var axios = require('axios');
var config = {
method: 'GET',
url: 'https://subdomain.zendesk.com/api/v2/chat/triggers',
headers: {
'Content-Type': 'application/json',
},
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Python
import requests
url = "https://subdomain.zendesk.com/api/v2/chat/triggers"
headers = {
"Content-Type": "application/json",
}
response = requests.request(
"GET",
url,
headers=headers
)
print(response.text)
Ruby
require "net/http"
uri = URI("https://subdomain.zendesk.com/api/v2/chat/triggers")
request = Net::HTTP::Get.new(uri, "Content-Type": "application/json")
response = Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
[
{
"description": "Visitor entered page",
"enabled": 1,
"id": 4,
"name": "Good Trigger"
},
{
"description": "Visitor requested chat",
"enabled": 1,
"id": 5,
"name": "Better Trigger"
}
]
Show Trigger
GET /api/v2/chat/triggers/{trigger_name}
Returns trigger information by specifying its name.
Allowed for
- Administrator
Parameters
Name | Type | In | Required | Description |
---|---|---|---|---|
trigger_name | string | Path | true | The name of the trigger |
Code Samples
curl
curl https://{subdomain}.zendesk.com/api/v2/chat/triggers/{trigger_name} \
-v -H "Authorization: Bearer {token}"
Go
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
method := "GET"
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client {}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
import com.squareup.okhttp.*;
OkHttpClient client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
.newBuilder();
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("GET", null)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Nodejs
var axios = require('axios');
var config = {
method: 'GET',
url: 'https://subdomain.zendesk.com/api/v2/chat/triggers/1',
headers: {
'Content-Type': 'application/json',
},
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Python
import requests
url = "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
headers = {
"Content-Type": "application/json",
}
response = requests.request(
"GET",
url,
headers=headers
)
print(response.text)
Ruby
require "net/http"
uri = URI("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
request = Net::HTTP::Get.new(uri, "Content-Type": "application/json")
response = Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
{
"description": "Visitor entered page",
"enabled": 1,
"id": 4,
"name": "Good Trigger"
}
Create Trigger
POST /api/v2/chat/triggers
Adds a trigger to an account.
Allowed for
- Administrator
Code Samples
curl
curl https://{subdomain}.zendesk.com/api/v2/chat/triggers \
-d '{
"name" : "Good Trigger",
"enabled" : 1,
"description" : "Visitor requested chat"
}' \
-v -H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" -X POST
Go
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://subdomain.zendesk.com/api/v2/chat/triggers"
method := "POST"
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client {}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
import com.squareup.okhttp.*;
OkHttpClient client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://subdomain.zendesk.com/api/v2/chat/triggers")
.newBuilder();
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
"""
""");
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Nodejs
var axios = require('axios');
var config = {
method: 'POST',
url: 'https://subdomain.zendesk.com/api/v2/chat/triggers',
headers: {
'Content-Type': 'application/json',
},
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Python
import requests
url = "https://subdomain.zendesk.com/api/v2/chat/triggers"
headers = {
"Content-Type": "application/json",
}
response = requests.request(
"POST",
url,
headers=headers
)
print(response.text)
Ruby
require "net/http"
uri = URI("https://subdomain.zendesk.com/api/v2/chat/triggers")
request = Net::HTTP::Post.new(uri, "Content-Type": "application/json")
response = Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
http.request(request)
end
Example response(s)
201 Created
// Status 201 Created
{
"description": "Visitor requested chat",
"enabled": 1,
"id": 4,
"name": "Good Trigger"
}
Update Trigger
PUT /api/v2/chat/triggers/{trigger_name}
Updates the data of a trigger.
Allowed for
- Administrator
Parameters
Name | Type | In | Required | Description |
---|---|---|---|---|
trigger_name | string | Path | true | The name of the trigger |
Code Samples
curl
curl https://{subdomain}.zendesk.com/api/v2/chat/triggers/{trigger_name} \
-d '{
"name" : "Best Trigger",
"description" : "Visitor requested new chat"
}' \
-v -H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" -X PUT
Go
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
method := "PUT"
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client {}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
import com.squareup.okhttp.*;
OkHttpClient client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
.newBuilder();
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
"""
""");
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("PUT", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Nodejs
var axios = require('axios');
var config = {
method: 'PUT',
url: 'https://subdomain.zendesk.com/api/v2/chat/triggers/1',
headers: {
'Content-Type': 'application/json',
},
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Python
import requests
url = "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
headers = {
"Content-Type": "application/json",
}
response = requests.request(
"PUT",
url,
headers=headers
)
print(response.text)
Ruby
require "net/http"
uri = URI("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
request = Net::HTTP::Put.new(uri, "Content-Type": "application/json")
response = Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
{
"description": "Visitor requested new chat",
"enabled": 1,
"id": 4,
"name": "Best Trigger"
}
Delete Trigger
DELETE /api/v2/chat/triggers/{trigger_name}
Deletes a trigger.
Allowed for
- Administrator
Parameters
Name | Type | In | Required | Description |
---|---|---|---|---|
trigger_name | string | Path | true | The name of the trigger |
Code Samples
curl
curl https://{subdomain}.zendesk.com/api/v2/chat/triggers/{trigger_name} \
-v -H "Authorization: Bearer {token}" -X DELETE
Go
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
method := "DELETE"
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
client := &http.Client {}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
import com.squareup.okhttp.*;
OkHttpClient client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
.newBuilder();
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("DELETE", null)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Nodejs
var axios = require('axios');
var config = {
method: 'DELETE',
url: 'https://subdomain.zendesk.com/api/v2/chat/triggers/1',
headers: {
'Content-Type': 'application/json',
},
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Python
import requests
url = "https://subdomain.zendesk.com/api/v2/chat/triggers/1"
headers = {
"Content-Type": "application/json",
}
response = requests.request(
"DELETE",
url,
headers=headers
)
print(response.text)
Ruby
require "net/http"
uri = URI("https://subdomain.zendesk.com/api/v2/chat/triggers/1")
request = Net::HTTP::Delete.new(uri, "Content-Type": "application/json")
response = Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
http.request(request)
end
Example response(s)
204 No Content
// Status 204 No Content
null