Search and return JSON for open tickets.
curl -X GET https://subdomain.zendesk.com/api/v2/search.json \
-H "Accept: application/json" \
--data-urlencode "query=type:ticket status:open" \
-u zendesk_email:zendesk_password
var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
strResponseBody: WideString;
respStatusCode: Integer;
jsonResponse: TChilkatJsonObject;
facets: WideString;
next_page: WideString;
previous_page: WideString;
count: Integer;
i: Integer;
count_i: Integer;
url: WideString;
id: Integer;
external_id: WideString;
viaChannel: WideString;
viaSourceRel: WideString;
created_at: WideString;
updated_at: WideString;
type: WideString;
subject: WideString;
raw_subject: WideString;
description: WideString;
priority: WideString;
status: WideString;
recipient: WideString;
requester_id: Integer;
submitter_id: Integer;
assignee_id: Integer;
organization_id: Integer;
group_id: Integer;
forum_topic_id: WideString;
problem_id: WideString;
has_incidents: Integer;
is_public: Integer;
due_at: WideString;
satisfaction_rating: WideString;
brand_id: Integer;
allow_channelback: Integer;
result_type: WideString;
j: Integer;
count_j: Integer;
strVal: WideString;
begin
rest := TChilkatRest.Create(Self);
// URL: https://subdomain.zendesk.com/api/v2/search.json
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('subdomain.zendesk.com',port,bTls,bAutoReconnect);
if (success <> 1) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
rest.SetAuthBasic('zendesk_email','zendesk_password');
rest.AddQueryParam('query','type:ticket status:open');
rest.AddHeader('Accept','application/json');
strResponseBody := rest.FullRequestFormUrlEncoded('GET','/api/v2/search.json');
if (rest.LastMethodSuccess <> 1) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
respStatusCode := rest.ResponseStatusCode;
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(rest.ResponseHeader);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(strResponseBody);
Exit;
end;
jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.Load(strResponseBody);
facets := jsonResponse.StringOf('facets');
next_page := jsonResponse.StringOf('next_page');
previous_page := jsonResponse.StringOf('previous_page');
count := jsonResponse.IntOf('count');
i := 0;
count_i := jsonResponse.SizeOfArray('results');
while i < count_i do
begin
jsonResponse.I := i;
url := jsonResponse.StringOf('results[i].url');
id := jsonResponse.IntOf('results[i].id');
external_id := jsonResponse.StringOf('results[i].external_id');
viaChannel := jsonResponse.StringOf('results[i].via.channel');
viaSourceRel := jsonResponse.StringOf('results[i].via.source.rel');
created_at := jsonResponse.StringOf('results[i].created_at');
updated_at := jsonResponse.StringOf('results[i].updated_at');
type := jsonResponse.StringOf('results[i].type');
subject := jsonResponse.StringOf('results[i].subject');
raw_subject := jsonResponse.StringOf('results[i].raw_subject');
description := jsonResponse.StringOf('results[i].description');
priority := jsonResponse.StringOf('results[i].priority');
status := jsonResponse.StringOf('results[i].status');
recipient := jsonResponse.StringOf('results[i].recipient');
requester_id := jsonResponse.IntOf('results[i].requester_id');
submitter_id := jsonResponse.IntOf('results[i].submitter_id');
assignee_id := jsonResponse.IntOf('results[i].assignee_id');
organization_id := jsonResponse.IntOf('results[i].organization_id');
group_id := jsonResponse.IntOf('results[i].group_id');
forum_topic_id := jsonResponse.StringOf('results[i].forum_topic_id');
problem_id := jsonResponse.StringOf('results[i].problem_id');
has_incidents := jsonResponse.BoolOf('results[i].has_incidents');
is_public := jsonResponse.BoolOf('results[i].is_public');
due_at := jsonResponse.StringOf('results[i].due_at');
satisfaction_rating := jsonResponse.StringOf('results[i].satisfaction_rating');
brand_id := jsonResponse.IntOf('results[i].brand_id');
allow_channelback := jsonResponse.BoolOf('results[i].allow_channelback');
result_type := jsonResponse.StringOf('results[i].result_type');
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].collaborator_ids');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].follower_ids');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].email_cc_ids');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].tags');
while j < count_j do
begin
jsonResponse.J := j;
strVal := jsonResponse.StringOf('results[i].tags[j]');
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].custom_fields');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].sharing_agreement_ids');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].fields');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
j := 0;
count_j := jsonResponse.SizeOfArray('results[i].followup_ids');
while j < count_j do
begin
jsonResponse.J := j;
j := j + 1;
end;
i := i + 1;
end;
{
"results": [
{
"url": "https://chilkat.zendesk.com/api/v2/tickets/4.json",
"id": 4,
"external_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2018-04-14T21:06:06Z",
"updated_at": "2018-04-14T21:06:06Z",
"type": "incident",
"subject": "Fix bug in software",
"raw_subject": "Fix bug in software",
"description": "Fix a bug in the software...",
"priority": "urgent",
"status": "open",
"recipient": null,
"requester_id": 361801727573,
"submitter_id": 361801727573,
"assignee_id": 361801727573,
"organization_id": 360015071793,
"group_id": 360000681553,
"collaborator_ids": [
],
"follower_ids": [
],
"email_cc_ids": [
],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [
"bug"
],
"custom_fields": [
],
"satisfaction_rating": null,
"sharing_agreement_ids": [
],
"fields": [
],
"followup_ids": [
],
"brand_id": 360000471533,
"allow_channelback": false,
"result_type": "ticket"
},
{
"url": "https://chilkat.zendesk.com/api/v2/tickets/3.json",
"id": 3,
"external_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2018-04-14T21:03:21Z",
"updated_at": "2018-04-14T21:03:21Z",
"type": "task",
"subject": "Add cool new feature.",
"raw_subject": "Add cool new feature.",
"description": "Add a cool new feature to the product.",
"priority": "high",
"status": "open",
"recipient": null,
"requester_id": 361801727573,
"submitter_id": 361801727573,
"assignee_id": 361801727573,
"organization_id": 360015071793,
"group_id": 360000681553,
"collaborator_ids": [
],
"follower_ids": [
],
"email_cc_ids": [
],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": "2018-04-18T17:00:00Z",
"tags": [
"cool",
"feature"
],
"custom_fields": [
],
"satisfaction_rating": null,
"sharing_agreement_ids": [
],
"fields": [
],
"followup_ids": [
],
"brand_id": 360000471533,
"allow_channelback": false,
"result_type": "ticket"
},
{
"url": "https://chilkat.zendesk.com/api/v2/tickets/1.json",
"id": 1,
"external_id": null,
"via": {
"channel": "sample_ticket",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2018-04-14T19:01:56Z",
"updated_at": "2018-04-14T19:01:57Z",
"type": "incident",
"subject": "Sample ticket: Meet the ticket",
"raw_subject": "Sample ticket: Meet the ticket",
"description": "Hi Matt,\n\nEmails, chats, voicemails, and tweets are captured in Zendesk Support as tickets. Start typing above to respond and click Submit to send. To test how an email becomes a ticket, send a message to support@chilkat.zendesk.com.\n\nCurious about what your customers will see when you reply? Check out this video:\nhttps://demos.zendesk.com/hc/en-us/articles/202341799\n",
"priority": "normal",
"status": "open",
"recipient": null,
"requester_id": 361809055094,
"submitter_id": 361801727573,
"assignee_id": 361801727573,
"organization_id": null,
"group_id": 360000681553,
"collaborator_ids": [
],
"follower_ids": [
],
"email_cc_ids": [
],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [
"sample",
"support",
"zendesk"
],
"custom_fields": [
],
"satisfaction_rating": null,
"sharing_agreement_ids": [
],
"fields": [
],
"followup_ids": [
],
"brand_id": 360000471533,
"allow_channelback": false,
"result_type": "ticket"
}
],
"facets": null,
"next_page": null,
"previous_page": null,
"count": 3
}