Chilkat Online Tools

PureBasic / Zoho CRM REST APIs / Job Details

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.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

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

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

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/crm/bulk/v2/write/{{job_id}}",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    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 = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "status": "INPROGRESS",
    ;   "resource": [
    ;     {
    ;       "status": "INPROGRESS",
    ;       "type": "data",
    ;       "module": "Leads",
    ;       "field_mappings": [
    ;         {
    ;           "api_name": "Owner",
    ;           "index": 1,
    ;           "format": null,
    ;           "find_by": null,
    ;           "module": null,
    ;           "default_value": null
    ;         },
    ;         {
    ;           "api_name": "Date_3",
    ;           "index": 2,
    ;           "format": "yyyy/MM/dd",
    ;           "find_by": null,
    ;           "module": null,
    ;           "default_value": null
    ;         },
    ;         {
    ;           "api_name": "Last_Name",
    ;           "index": 0,
    ;           "format": null,
    ;           "find_by": null,
    ;           "module": null,
    ;           "default_value": null
    ;         },
    ;         {
    ;           "api_name": "Layout",
    ;           "index": 4,
    ;           "format": null,
    ;           "find_by": null,
    ;           "module": null,
    ;           "default_value": null
    ;         },
    ;         {
    ;           "api_name": "Mobile",
    ;           "index": 3,
    ;           "format": null,
    ;           "find_by": null,
    ;           "module": null,
    ;           "default_value": null
    ;         }
    ;       ],
    ;       "code": "INPROGRESS"
    ;     }
    ;   ],
    ;   "id": "4150868000005392002",
    ;   "callback": {
    ;     "url": "https://www.zoho.com/in/crm/",
    ;     "method": "post"
    ;   },
    ;   "created_by": {
    ;     "id": "4150868000000225013",
    ;     "name": "Patricia Boyle"
    ;   },
    ;   "ignore_empty": true,
    ;   "operation": "insert",
    ;   "created_time": "2021-05-13T11:00:58+05:30"
    ; }

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

    v_type.s
    module.s
    code.s
    j.i
    count_j.i
    api_name.s
    index.i
    format.s
    find_by.s
    default_value.s

    status.s = CkJsonObject::ckStringOf(jResp,"status")
    id.s = CkJsonObject::ckStringOf(jResp,"id")
    v_Url.s = CkJsonObject::ckStringOf(jResp,"callback.url")
    Method.s = CkJsonObject::ckStringOf(jResp,"callback.method")
    Id.s = CkJsonObject::ckStringOf(jResp,"created_by.id")
    Name.s = CkJsonObject::ckStringOf(jResp,"created_by.name")
    ignore_empty.i = CkJsonObject::ckBoolOf(jResp,"ignore_empty")
    operation.s = CkJsonObject::ckStringOf(jResp,"operation")
    created_time.s = CkJsonObject::ckStringOf(jResp,"created_time")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"resource")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        status = CkJsonObject::ckStringOf(jResp,"resource[i].status")
        v_type = CkJsonObject::ckStringOf(jResp,"resource[i].type")
        module = CkJsonObject::ckStringOf(jResp,"resource[i].module")
        code = CkJsonObject::ckStringOf(jResp,"resource[i].code")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"resource[i].field_mappings")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            api_name = CkJsonObject::ckStringOf(jResp,"resource[i].field_mappings[j].api_name")
            index = CkJsonObject::ckIntOf(jResp,"resource[i].field_mappings[j].index")
            format = CkJsonObject::ckStringOf(jResp,"resource[i].field_mappings[j].format")
            find_by = CkJsonObject::ckStringOf(jResp,"resource[i].field_mappings[j].find_by")
            module = CkJsonObject::ckStringOf(jResp,"resource[i].field_mappings[j].module")
            default_value = CkJsonObject::ckStringOf(jResp,"resource[i].field_mappings[j].default_value")
            j = j + 1
        Wend
        i = i + 1
    Wend


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


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/crm/bulk/v2/write/{{job_id}}

Postman Collection Item JSON

{
  "name": "Job Details",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{api-domain}}/crm/bulk/v2/write/{{job_id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "bulk",
        "v2",
        "write",
        "{{job_id}}"
      ]
    },
    "description": "To get the details of a bulk write job performed previously."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2/write/4150868000005392002",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "write",
            "4150868000005392002"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:33:49 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-13T12:00:55+05:30"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"status\": \"INPROGRESS\",\n    \"resource\": [\n        {\n            \"status\": \"INPROGRESS\",\n            \"type\": \"data\",\n            \"module\": \"Leads\",\n            \"field_mappings\": [\n                {\n                    \"api_name\": \"Owner\",\n                    \"index\": 1,\n                    \"format\": null,\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                },\n                {\n                    \"api_name\": \"Date_3\",\n                    \"index\": 2,\n                    \"format\": \"yyyy/MM/dd\",\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                },\n                {\n                    \"api_name\": \"Last_Name\",\n                    \"index\": 0,\n                    \"format\": null,\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                },\n                {\n                    \"api_name\": \"Layout\",\n                    \"index\": 4,\n                    \"format\": null,\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                },\n                {\n                    \"api_name\": \"Mobile\",\n                    \"index\": 3,\n                    \"format\": null,\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                }\n            ],\n            \"code\": \"INPROGRESS\"\n        }\n    ],\n    \"id\": \"4150868000005392002\",\n    \"callback\": {\n        \"url\": \"https://www.zoho.com/in/crm/\",\n        \"method\": \"post\"\n    },\n    \"created_by\": {\n        \"id\": \"4150868000000225013\",\n        \"name\": \"Patricia Boyle\"\n    },\n    \"ignore_empty\": true,\n    \"operation\": \"insert\",\n    \"created_time\": \"2021-05-13T11:00:58+05:30\"\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2/writ/4150868000005392002",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "writ",
            "4150868000005392002"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:34:11 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "131"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_URL_PATTERN\",\n    \"details\": {},\n    \"message\": \"Please check if the URL trying to access is a correct one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_REQUEST_METHOD",
      "originalRequest": {
        "method": "COPY",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2/write/4150868000005392002",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "write",
            "4150868000005392002"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:34:36 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "124"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_REQUEST_METHOD\",\n    \"details\": {},\n    \"message\": \"The http request method type is not a valid one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "AUTHENTICATION_FAILURE",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2/write/4150868000005392002",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "write",
            "4150868000005392002"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:34:55 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "98"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"AUTHENTICATION_FAILURE\",\n    \"details\": {},\n    \"message\": \"Authentication failed\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "RESOURCE_NOT_FOUND",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2/write/415086800000539200",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "write",
            "415086800000539200"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:35:14 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-13T12:00:55+05:30"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"status\": \"error\",\n    \"code\": \"RESOURCE_NOT_FOUND\",\n    \"message\": \"The requested resource doesn't exist.\",\n    \"details\": {}\n}"
    }
  ]
}