Chilkat Online Tools

PureBasic / Support API / List Custom Object Records

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,"external_ids[]","<string>")
    CkJsonObject::ckUpdateString(queryParams,"external_ids[]","<string>")

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

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/custom_objects/:custom_object_key/records",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>",
    ;   "custom_object_records": [
    ;     {
    ;       "name": "<string>",
    ;       "created_at": "<dateTime>",
    ;       "created_by_user_id": "<string>",
    ;       "custom_object_fields": {
    ;         "voluptate571": "<string>",
    ;         "aute_e": "<string>",
    ;         "nostrud_6f": "<string>"
    ;       },
    ;       "custom_object_key": "<string>",
    ;       "external_id": "<string>",
    ;       "id": "<string>",
    ;       "updated_at": "<dateTime>",
    ;       "updated_by_user_id": "<string>",
    ;       "url": "<string>"
    ;     },
    ;     {
    ;       "name": "<string>",
    ;       "created_at": "<dateTime>",
    ;       "created_by_user_id": "<string>",
    ;       "custom_object_fields": {
    ;         "eu4": "<string>"
    ;       },
    ;       "custom_object_key": "<string>",
    ;       "external_id": "<string>",
    ;       "id": "<string>",
    ;       "updated_at": "<dateTime>",
    ;       "updated_by_user_id": "<string>",
    ;       "url": "<string>"
    ;     }
    ;   ],
    ;   "next_page": "<string>",
    ;   "previous_page": "<string>"
    ; }

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

    name.s
    created_at.s
    created_by_user_id.s
    Voluptate571.s
    Aute_e.s
    Nostrud_6f.s
    custom_object_key.s
    external_id.s
    id.s
    updated_at.s
    updated_by_user_id.s
    url.s
    Eu4.s

    count.s = CkJsonObject::ckStringOf(jResp,"count")
    next_page.s = CkJsonObject::ckStringOf(jResp,"next_page")
    previous_page.s = CkJsonObject::ckStringOf(jResp,"previous_page")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"custom_object_records")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        name = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].name")
        created_at = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].created_at")
        created_by_user_id = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].created_by_user_id")
        Voluptate571 = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].custom_object_fields.voluptate571")
        Aute_e = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].custom_object_fields.aute_e")
        Nostrud_6f = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].custom_object_fields.nostrud_6f")
        custom_object_key = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].custom_object_key")
        external_id = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].external_id")
        id = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].id")
        updated_at = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].updated_at")
        updated_by_user_id = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].updated_by_user_id")
        url = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].url")
        Eu4 = CkJsonObject::ckStringOf(jResp,"custom_object_records[i].custom_object_fields.eu4")
        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 "external_ids[]=%3Cstring%3E"
	-d "external_ids[]=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/custom_objects/:custom_object_key/records

Postman Collection Item JSON

{
  "name": "List Custom Object Records",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/custom_objects/:custom_object_key/records?external_ids[]=<string>&external_ids[]=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "custom_objects",
        ":custom_object_key",
        "records"
      ],
      "query": [
        {
          "key": "external_ids[]",
          "value": "<string>",
          "description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
        },
        {
          "key": "external_ids[]",
          "value": "<string>",
          "description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
        }
      ],
      "variable": [
        {
          "key": "custom_object_key",
          "value": "<string>"
        }
      ]
    },
    "description": "Lists all undeleted custom object records for the specified object\n#### Allowed For\n* Everyone"
  },
  "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/custom_objects/:custom_object_key/records?external_ids[]=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "custom_objects",
            ":custom_object_key",
            "records"
          ],
          "query": [
            {
              "key": "external_ids[]",
              "value": "<string>",
              "description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
            }
          ],
          "variable": [
            {
              "key": "custom_object_key"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"count\": \"<integer>\",\n  \"custom_object_records\": [\n    {\n      \"name\": \"<string>\",\n      \"created_at\": \"<dateTime>\",\n      \"created_by_user_id\": \"<string>\",\n      \"custom_object_fields\": {\n        \"voluptate571\": \"<string>\",\n        \"aute_e\": \"<string>\",\n        \"nostrud_6f\": \"<string>\"\n      },\n      \"custom_object_key\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"id\": \"<string>\",\n      \"updated_at\": \"<dateTime>\",\n      \"updated_by_user_id\": \"<string>\",\n      \"url\": \"<string>\"\n    },\n    {\n      \"name\": \"<string>\",\n      \"created_at\": \"<dateTime>\",\n      \"created_by_user_id\": \"<string>\",\n      \"custom_object_fields\": {\n        \"eu4\": \"<string>\"\n      },\n      \"custom_object_key\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"id\": \"<string>\",\n      \"updated_at\": \"<dateTime>\",\n      \"updated_by_user_id\": \"<string>\",\n      \"url\": \"<string>\"\n    }\n  ],\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\"\n}"
    }
  ]
}