C# UWP/WinRT Zendesk: Search for Open Tickets

Back to Index

Search and return JSON for open tickets.

Documentation: https://developer.zendesk.com/rest_api/docs/core/search

CURL Command

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

C# UWP/WinRT Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://subdomain.zendesk.com/api/v2/search.json
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = await rest.ConnectAsync("subdomain.zendesk.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

rest.SetAuthBasic("zendesk_email","zendesk_password");

rest.AddQueryParam("query","type:ticket status:open");

rest.AddHeader("Accept","application/json");

string strResponseBody = await rest.FullRequestFormUrlEncodedAsync("GET","/api/v2/search.json");
if (rest.LastMethodSuccess != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

int respStatusCode = rest.ResponseStatusCode;
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(rest.ResponseHeader);
    Debug.WriteLine("Response Body:");
    Debug.WriteLine(strResponseBody);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.Load(strResponseBody);

string facets;
string next_page;
string previous_page;
int count;
int i;
int count_i;
string url;
int id;
string external_id;
string viaChannel;
string viaSourceRel;
string created_at;
string updated_at;
string type;
string subject;
string raw_subject;
string description;
string priority;
string status;
string recipient;
int requester_id;
int submitter_id;
int assignee_id;
int organization_id;
int group_id;
string forum_topic_id;
string problem_id;
bool has_incidents;
bool is_public;
string due_at;
string satisfaction_rating;
int brand_id;
bool allow_channelback;
string result_type;
int j;
int count_j;
string strVal;

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) {
    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) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].follower_ids");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].email_cc_ids");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].tags");
    while (j < count_j) {
        jsonResponse.J = j;
        strVal = jsonResponse.StringOf("results[i].tags[j]");
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].custom_fields");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].sharing_agreement_ids");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].fields");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    j = 0;
    count_j = jsonResponse.SizeOfArray("results[i].followup_ids");
    while (j < count_j) {
        jsonResponse.J = j;
        j = j + 1;
    }

    i = i + 1;
}

Sample JSON Response Body

{
  "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
}