Chilkat Online Tools

PureBasic / Support API / Incremental Ticket Export, Time Based

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

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

    success.i

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "login")
    CkHttp::setCkPassword(http, "password")

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

    CkJsonObject::ckUpdateString(queryParams,"start_time","<integer>")

    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/incremental/tickets",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

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

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

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

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "count": "<integer>",
    ;   "end_of_stream": "<boolean>",
    ;   "end_time": "<integer>",
    ;   "next_page": "<string>",
    ;   "tickets": [
    ;     {
    ;       "requester_id": "<integer>",
    ;       "allow_attachments": "<boolean>",
    ;       "allow_channelback": "<boolean>",
    ;       "assignee_email": "<string>",
    ;       "assignee_id": "<integer>",
    ;       "attribute_value_ids": "<array>",
    ;       "brand_id": "<integer>",
    ;       "collaborator_ids": "<array>",
    ;       "collaborators": [
    ;         {
    ;           "email": "<email>",
    ;           "name": "<string>"
    ;         },
    ;         {
    ;           "email": "<email>",
    ;           "name": "<string>"
    ;         }
    ;       ],
    ;       "comment": {},
    ;       "created_at": "<dateTime>",
    ;       "custom_fields": "<array>",
    ;       "custom_status_id": "<integer>",
    ;       "description": "<string>",
    ;       "due_at": "<dateTime>",
    ;       "email_cc_ids": "<array>",
    ;       "email_ccs": {},
    ;       "external_id": "<string>",
    ;       "follower_ids": "<array>",
    ;       "followers": {},
    ;       "followup_ids": "<array>",
    ;       "forum_topic_id": "<integer>",
    ;       "from_messaging_channel": "<boolean>",
    ;       "group_id": "<integer>",
    ;       "has_incidents": "<boolean>",
    ;       "id": "<integer>",
    ;       "is_public": "<boolean>",
    ;       "macro_id": "<integer>",
    ;       "macro_ids": "<array>",
    ;       "metadata": {},
    ;       "organization_id": "<integer>",
    ;       "priority": "high",
    ;       "problem_id": "<integer>",
    ;       "raw_subject": "<string>",
    ;       "recipient": "<string>",
    ;       "requester": {},
    ;       "safe_update": "<boolean>",
    ;       "satisfaction_rating": {
    ;         "aliquad0": false
    ;       },
    ;       "sharing_agreement_ids": "<array>",
    ;       "status": "pending",
    ;       "subject": "<string>",
    ;       "submitter_id": "<integer>",
    ;       "tags": "<array>",
    ;       "ticket_form_id": "<integer>",
    ;       "type": "question",
    ;       "updated_at": "<dateTime>",
    ;       "updated_stamp": "<string>",
    ;       "url": "<string>",
    ;       "via": {
    ;         "channel": "<string>",
    ;         "source": {
    ;           "elit2f": -86657295.30733354
    ;         }
    ;       },
    ;       "via_followup_source_id": "<integer>",
    ;       "via_id": "<integer>",
    ;       "voice_comment": {}
    ;     },
    ;     {
    ;       "requester_id": "<integer>",
    ;       "allow_attachments": "<boolean>",
    ;       "allow_channelback": "<boolean>",
    ;       "assignee_email": "<string>",
    ;       "assignee_id": "<integer>",
    ;       "attribute_value_ids": "<array>",
    ;       "brand_id": "<integer>",
    ;       "collaborator_ids": "<array>",
    ;       "collaborators": [
    ;         {
    ;           "email": "<email>",
    ;           "name": "<string>"
    ;         },
    ;         {
    ;           "email": "<email>",
    ;           "name": "<string>"
    ;         }
    ;       ],
    ;       "comment": {},
    ;       "created_at": "<dateTime>",
    ;       "custom_fields": "<array>",
    ;       "custom_status_id": "<integer>",
    ;       "description": "<string>",
    ;       "due_at": "<dateTime>",
    ;       "email_cc_ids": "<array>",
    ;       "email_ccs": {},
    ;       "external_id": "<string>",
    ;       "follower_ids": "<array>",
    ;       "followers": {},
    ;       "followup_ids": "<array>",
    ;       "forum_topic_id": "<integer>",
    ;       "from_messaging_channel": "<boolean>",
    ;       "group_id": "<integer>",
    ;       "has_incidents": "<boolean>",
    ;       "id": "<integer>",
    ;       "is_public": "<boolean>",
    ;       "macro_id": "<integer>",
    ;       "macro_ids": "<array>",
    ;       "metadata": {},
    ;       "organization_id": "<integer>",
    ;       "priority": "high",
    ;       "problem_id": "<integer>",
    ;       "raw_subject": "<string>",
    ;       "recipient": "<string>",
    ;       "requester": {},
    ;       "safe_update": "<boolean>",
    ;       "satisfaction_rating": {
    ;         "minim_01": "minim tempor",
    ;         "ipsum8c2": false
    ;       },
    ;       "sharing_agreement_ids": "<array>",
    ;       "status": "open",
    ;       "subject": "<string>",
    ;       "submitter_id": "<integer>",
    ;       "tags": "<array>",
    ;       "ticket_form_id": "<integer>",
    ;       "type": "task",
    ;       "updated_at": "<dateTime>",
    ;       "updated_stamp": "<string>",
    ;       "url": "<string>",
    ;       "via": {
    ;         "channel": "<string>",
    ;         "source": {
    ;           "nostrud_ee": "dolore veniam consequat"
    ;         }
    ;       },
    ;       "via_followup_source_id": "<integer>",
    ;       "via_id": "<integer>",
    ;       "voice_comment": {}
    ;     }
    ;   ]
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    requester_id.s
    allow_attachments.s
    allow_channelback.s
    assignee_email.s
    assignee_id.s
    attribute_value_ids.s
    brand_id.s
    collaborator_ids.s
    created_at.s
    custom_fields.s
    custom_status_id.s
    description.s
    due_at.s
    email_cc_ids.s
    external_id.s
    follower_ids.s
    followup_ids.s
    forum_topic_id.s
    from_messaging_channel.s
    group_id.s
    has_incidents.s
    id.s
    is_public.s
    macro_id.s
    macro_ids.s
    organization_id.s
    priority.s
    problem_id.s
    raw_subject.s
    recipient.s
    safe_update.s
    Aliquad0.i
    sharing_agreement_ids.s
    status.s
    subject.s
    submitter_id.s
    tags.s
    ticket_form_id.s
    v_type.s
    updated_at.s
    updated_stamp.s
    url.s
    Channel.s
    Elit2f.s
    via_followup_source_id.s
    via_id.s
    Minim_01.s
    Ipsum8c2.i
    Nostrud_ee.s
    j.i
    count_j.i
    email.s
    name.s

    count.s = CkJsonObject::ckStringOf(jResp,"count")
    end_of_stream.s = CkJsonObject::ckStringOf(jResp,"end_of_stream")
    end_time.s = CkJsonObject::ckStringOf(jResp,"end_time")
    next_page.s = CkJsonObject::ckStringOf(jResp,"next_page")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"tickets")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        requester_id = CkJsonObject::ckStringOf(jResp,"tickets[i].requester_id")
        allow_attachments = CkJsonObject::ckStringOf(jResp,"tickets[i].allow_attachments")
        allow_channelback = CkJsonObject::ckStringOf(jResp,"tickets[i].allow_channelback")
        assignee_email = CkJsonObject::ckStringOf(jResp,"tickets[i].assignee_email")
        assignee_id = CkJsonObject::ckStringOf(jResp,"tickets[i].assignee_id")
        attribute_value_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].attribute_value_ids")
        brand_id = CkJsonObject::ckStringOf(jResp,"tickets[i].brand_id")
        collaborator_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].collaborator_ids")
        created_at = CkJsonObject::ckStringOf(jResp,"tickets[i].created_at")
        custom_fields = CkJsonObject::ckStringOf(jResp,"tickets[i].custom_fields")
        custom_status_id = CkJsonObject::ckStringOf(jResp,"tickets[i].custom_status_id")
        description = CkJsonObject::ckStringOf(jResp,"tickets[i].description")
        due_at = CkJsonObject::ckStringOf(jResp,"tickets[i].due_at")
        email_cc_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].email_cc_ids")
        external_id = CkJsonObject::ckStringOf(jResp,"tickets[i].external_id")
        follower_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].follower_ids")
        followup_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].followup_ids")
        forum_topic_id = CkJsonObject::ckStringOf(jResp,"tickets[i].forum_topic_id")
        from_messaging_channel = CkJsonObject::ckStringOf(jResp,"tickets[i].from_messaging_channel")
        group_id = CkJsonObject::ckStringOf(jResp,"tickets[i].group_id")
        has_incidents = CkJsonObject::ckStringOf(jResp,"tickets[i].has_incidents")
        id = CkJsonObject::ckStringOf(jResp,"tickets[i].id")
        is_public = CkJsonObject::ckStringOf(jResp,"tickets[i].is_public")
        macro_id = CkJsonObject::ckStringOf(jResp,"tickets[i].macro_id")
        macro_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].macro_ids")
        organization_id = CkJsonObject::ckStringOf(jResp,"tickets[i].organization_id")
        priority = CkJsonObject::ckStringOf(jResp,"tickets[i].priority")
        problem_id = CkJsonObject::ckStringOf(jResp,"tickets[i].problem_id")
        raw_subject = CkJsonObject::ckStringOf(jResp,"tickets[i].raw_subject")
        recipient = CkJsonObject::ckStringOf(jResp,"tickets[i].recipient")
        safe_update = CkJsonObject::ckStringOf(jResp,"tickets[i].safe_update")
        Aliquad0 = CkJsonObject::ckBoolOf(jResp,"tickets[i].satisfaction_rating.aliquad0")
        sharing_agreement_ids = CkJsonObject::ckStringOf(jResp,"tickets[i].sharing_agreement_ids")
        status = CkJsonObject::ckStringOf(jResp,"tickets[i].status")
        subject = CkJsonObject::ckStringOf(jResp,"tickets[i].subject")
        submitter_id = CkJsonObject::ckStringOf(jResp,"tickets[i].submitter_id")
        tags = CkJsonObject::ckStringOf(jResp,"tickets[i].tags")
        ticket_form_id = CkJsonObject::ckStringOf(jResp,"tickets[i].ticket_form_id")
        v_type = CkJsonObject::ckStringOf(jResp,"tickets[i].type")
        updated_at = CkJsonObject::ckStringOf(jResp,"tickets[i].updated_at")
        updated_stamp = CkJsonObject::ckStringOf(jResp,"tickets[i].updated_stamp")
        url = CkJsonObject::ckStringOf(jResp,"tickets[i].url")
        Channel = CkJsonObject::ckStringOf(jResp,"tickets[i].via.channel")
        Elit2f = CkJsonObject::ckStringOf(jResp,"tickets[i].via.source.elit2f")
        via_followup_source_id = CkJsonObject::ckStringOf(jResp,"tickets[i].via_followup_source_id")
        via_id = CkJsonObject::ckStringOf(jResp,"tickets[i].via_id")
        Minim_01 = CkJsonObject::ckStringOf(jResp,"tickets[i].satisfaction_rating.minim_01")
        Ipsum8c2 = CkJsonObject::ckBoolOf(jResp,"tickets[i].satisfaction_rating.ipsum8c2")
        Nostrud_ee = CkJsonObject::ckStringOf(jResp,"tickets[i].via.source.nostrud_ee")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"tickets[i].collaborators")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            email = CkJsonObject::ckStringOf(jResp,"tickets[i].collaborators[j].email")
            name = CkJsonObject::ckStringOf(jResp,"tickets[i].collaborators[j].name")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl  -u login:password -G -d "start_time=%3Cinteger%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/incremental/tickets

Postman Collection Item JSON

{
  "name": "Incremental Ticket Export, Time Based",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/incremental/tickets?start_time=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "incremental",
        "tickets"
      ],
      "query": [
        {
          "key": "start_time",
          "value": "<integer>",
          "description": "(Required) The time to start the incremental export from"
        }
      ]
    },
    "description": "Returns the tickets that changed since the start time. For more information,\nsee [Exporting tickets](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#exporting-tickets) in [Using the Incremental Exports API](/documentation/ticketing/managing-tickets/using-the-incremental-export-api).\n\nThis endpoint supports time-based incremental exports.\nFor more information, see [Time-based incremental exports](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#time-based-incremental-exports) in [Using the Incremental Exports API](/documentation/ticketing/managing-tickets/using-the-incremental-export-api). You can also return tickets using cursor-based pagination. See [Incremental Ticket Export, Cursor Based](#incremental-ticket-export-cursor-based).\n\nThe results include tickets that were updated by the system. See\n[Excluding system-updated tickets](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#excluding-system-updated-tickets-time-based-exports) in [Using the Incremental Exports API](/documentation/ticketing/managing-tickets/using-the-incremental-export-api).\n\nThe endpoint can return tickets with an `updated_at` time that's earlier than the\n`start_time` time. The reason is that the API compares the `start_time` with the ticket's\n`generated_timestamp` value, not its `updated_at` value. The `updated_at` value is\nupdated only if the update generates a [ticket event](#incremental-ticket-event-export).\nThe `generated_timestamp` value is updated for all ticket updates, including system\nupdates. If a system update occurs after a ticket event, the unchanged\n`updated_at` time will become earlier relative to the updated `generated_timestamp`\ntime.\n\n#### Allowed For\n\n * Admins\n\n#### Sideloading\n\nSee [Tickets sideloads](/documentation/ticketing/using-the-zendesk-api/side_loading/#supported-endpoints). For performance reasons,\n`last_audits` sideloads aren't supported.\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/incremental/tickets?start_time=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "incremental",
            "tickets"
          ],
          "query": [
            {
              "key": "start_time",
              "value": "<integer>",
              "description": "(Required) The time to start the incremental export from"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"count\": \"<integer>\",\n  \"end_of_stream\": \"<boolean>\",\n  \"end_time\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"tickets\": [\n    {\n      \"requester_id\": \"<integer>\",\n      \"allow_attachments\": \"<boolean>\",\n      \"allow_channelback\": \"<boolean>\",\n      \"assignee_email\": \"<string>\",\n      \"assignee_id\": \"<integer>\",\n      \"attribute_value_ids\": \"<array>\",\n      \"brand_id\": \"<integer>\",\n      \"collaborator_ids\": \"<array>\",\n      \"collaborators\": [\n        {\n          \"email\": \"<email>\",\n          \"name\": \"<string>\"\n        },\n        {\n          \"email\": \"<email>\",\n          \"name\": \"<string>\"\n        }\n      ],\n      \"comment\": {},\n      \"created_at\": \"<dateTime>\",\n      \"custom_fields\": \"<array>\",\n      \"custom_status_id\": \"<integer>\",\n      \"description\": \"<string>\",\n      \"due_at\": \"<dateTime>\",\n      \"email_cc_ids\": \"<array>\",\n      \"email_ccs\": {},\n      \"external_id\": \"<string>\",\n      \"follower_ids\": \"<array>\",\n      \"followers\": {},\n      \"followup_ids\": \"<array>\",\n      \"forum_topic_id\": \"<integer>\",\n      \"from_messaging_channel\": \"<boolean>\",\n      \"group_id\": \"<integer>\",\n      \"has_incidents\": \"<boolean>\",\n      \"id\": \"<integer>\",\n      \"is_public\": \"<boolean>\",\n      \"macro_id\": \"<integer>\",\n      \"macro_ids\": \"<array>\",\n      \"metadata\": {},\n      \"organization_id\": \"<integer>\",\n      \"priority\": \"high\",\n      \"problem_id\": \"<integer>\",\n      \"raw_subject\": \"<string>\",\n      \"recipient\": \"<string>\",\n      \"requester\": {},\n      \"safe_update\": \"<boolean>\",\n      \"satisfaction_rating\": {\n        \"aliquad0\": false\n      },\n      \"sharing_agreement_ids\": \"<array>\",\n      \"status\": \"pending\",\n      \"subject\": \"<string>\",\n      \"submitter_id\": \"<integer>\",\n      \"tags\": \"<array>\",\n      \"ticket_form_id\": \"<integer>\",\n      \"type\": \"question\",\n      \"updated_at\": \"<dateTime>\",\n      \"updated_stamp\": \"<string>\",\n      \"url\": \"<string>\",\n      \"via\": {\n        \"channel\": \"<string>\",\n        \"source\": {\n          \"elit2f\": -86657295.30733354\n        }\n      },\n      \"via_followup_source_id\": \"<integer>\",\n      \"via_id\": \"<integer>\",\n      \"voice_comment\": {}\n    },\n    {\n      \"requester_id\": \"<integer>\",\n      \"allow_attachments\": \"<boolean>\",\n      \"allow_channelback\": \"<boolean>\",\n      \"assignee_email\": \"<string>\",\n      \"assignee_id\": \"<integer>\",\n      \"attribute_value_ids\": \"<array>\",\n      \"brand_id\": \"<integer>\",\n      \"collaborator_ids\": \"<array>\",\n      \"collaborators\": [\n        {\n          \"email\": \"<email>\",\n          \"name\": \"<string>\"\n        },\n        {\n          \"email\": \"<email>\",\n          \"name\": \"<string>\"\n        }\n      ],\n      \"comment\": {},\n      \"created_at\": \"<dateTime>\",\n      \"custom_fields\": \"<array>\",\n      \"custom_status_id\": \"<integer>\",\n      \"description\": \"<string>\",\n      \"due_at\": \"<dateTime>\",\n      \"email_cc_ids\": \"<array>\",\n      \"email_ccs\": {},\n      \"external_id\": \"<string>\",\n      \"follower_ids\": \"<array>\",\n      \"followers\": {},\n      \"followup_ids\": \"<array>\",\n      \"forum_topic_id\": \"<integer>\",\n      \"from_messaging_channel\": \"<boolean>\",\n      \"group_id\": \"<integer>\",\n      \"has_incidents\": \"<boolean>\",\n      \"id\": \"<integer>\",\n      \"is_public\": \"<boolean>\",\n      \"macro_id\": \"<integer>\",\n      \"macro_ids\": \"<array>\",\n      \"metadata\": {},\n      \"organization_id\": \"<integer>\",\n      \"priority\": \"high\",\n      \"problem_id\": \"<integer>\",\n      \"raw_subject\": \"<string>\",\n      \"recipient\": \"<string>\",\n      \"requester\": {},\n      \"safe_update\": \"<boolean>\",\n      \"satisfaction_rating\": {\n        \"minim_01\": \"minim tempor\",\n        \"ipsum8c2\": false\n      },\n      \"sharing_agreement_ids\": \"<array>\",\n      \"status\": \"open\",\n      \"subject\": \"<string>\",\n      \"submitter_id\": \"<integer>\",\n      \"tags\": \"<array>\",\n      \"ticket_form_id\": \"<integer>\",\n      \"type\": \"task\",\n      \"updated_at\": \"<dateTime>\",\n      \"updated_stamp\": \"<string>\",\n      \"url\": \"<string>\",\n      \"via\": {\n        \"channel\": \"<string>\",\n        \"source\": {\n          \"nostrud_ee\": \"dolore veniam consequat\"\n        }\n      },\n      \"via_followup_source_id\": \"<integer>\",\n      \"via_id\": \"<integer>\",\n      \"voice_comment\": {}\n    }\n  ]\n}"
    }
  ]
}