PureBasic 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

PureBasic Example

IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://subdomain.zendesk.com/api/v2/search.json
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"subdomain.zendesk.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"zendesk_email","zendesk_password")

    CkRest::ckAddQueryParam(rest,"query","type:ticket status:open")

    CkRest::ckAddHeader(rest,"Accept","application/json")

    strResponseBody.s = CkRest::ckFullRequestFormUrlEncoded(rest,"GET","/api/v2/search.json")
    If CkRest::ckLastMethodSuccess(rest) <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    respStatusCode.i = CkRest::ckResponseStatusCode(rest)
    If respStatusCode >= 400
        Debug "Response Status Code = " + Str(respStatusCode)
        Debug "Response Header:"
        Debug CkRest::ckResponseHeader(rest)
        Debug "Response Body:"
        Debug strResponseBody
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResponse,strResponseBody)

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

    facets = CkJsonObject::ckStringOf(jsonResponse,"facets")
    next_page = CkJsonObject::ckStringOf(jsonResponse,"next_page")
    previous_page = CkJsonObject::ckStringOf(jsonResponse,"previous_page")
    count = CkJsonObject::ckIntOf(jsonResponse,"count")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"results")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        url = CkJsonObject::ckStringOf(jsonResponse,"results[i].url")
        id = CkJsonObject::ckIntOf(jsonResponse,"results[i].id")
        external_id = CkJsonObject::ckStringOf(jsonResponse,"results[i].external_id")
        viaChannel = CkJsonObject::ckStringOf(jsonResponse,"results[i].via.channel")
        viaSourceRel = CkJsonObject::ckStringOf(jsonResponse,"results[i].via.source.rel")
        created_at = CkJsonObject::ckStringOf(jsonResponse,"results[i].created_at")
        updated_at = CkJsonObject::ckStringOf(jsonResponse,"results[i].updated_at")
        type = CkJsonObject::ckStringOf(jsonResponse,"results[i].type")
        subject = CkJsonObject::ckStringOf(jsonResponse,"results[i].subject")
        raw_subject = CkJsonObject::ckStringOf(jsonResponse,"results[i].raw_subject")
        description = CkJsonObject::ckStringOf(jsonResponse,"results[i].description")
        priority = CkJsonObject::ckStringOf(jsonResponse,"results[i].priority")
        status = CkJsonObject::ckStringOf(jsonResponse,"results[i].status")
        recipient = CkJsonObject::ckStringOf(jsonResponse,"results[i].recipient")
        requester_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].requester_id")
        submitter_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].submitter_id")
        assignee_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].assignee_id")
        organization_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].organization_id")
        group_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].group_id")
        forum_topic_id = CkJsonObject::ckStringOf(jsonResponse,"results[i].forum_topic_id")
        problem_id = CkJsonObject::ckStringOf(jsonResponse,"results[i].problem_id")
        has_incidents = CkJsonObject::ckBoolOf(jsonResponse,"results[i].has_incidents")
        is_public = CkJsonObject::ckBoolOf(jsonResponse,"results[i].is_public")
        due_at = CkJsonObject::ckStringOf(jsonResponse,"results[i].due_at")
        satisfaction_rating = CkJsonObject::ckStringOf(jsonResponse,"results[i].satisfaction_rating")
        brand_id = CkJsonObject::ckIntOf(jsonResponse,"results[i].brand_id")
        allow_channelback = CkJsonObject::ckBoolOf(jsonResponse,"results[i].allow_channelback")
        result_type = CkJsonObject::ckStringOf(jsonResponse,"results[i].result_type")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].collaborator_ids")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].follower_ids")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].email_cc_ids")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].tags")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            strVal = CkJsonObject::ckStringOf(jsonResponse,"results[i].tags[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].custom_fields")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].sharing_agreement_ids")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].fields")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].followup_ids")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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
}