Chilkat Online Tools

Python / Zoho CRM REST APIs / Get Bulk Read Job Details

Back to Collection Items

import sys
import chilkat2

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

http = chilkat2.Http()

# Adds the "Authorization: Bearer {{access-token}}" header.
http.AuthToken = "{{access-token}}"

sbResponseBody = chilkat2.StringBuilder()
success = http.QuickGetSb("https://www.zohoapis.com/crm/bulk/v2/read/{{job_id}}",sbResponseBody)
if (success == False):
    print(http.LastErrorText)
    sys.exit()

jResp = chilkat2.JsonObject()
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

print("Response Body:")
print(jResp.Emit())

respStatusCode = http.LastStatus
print("Response Status Code = " + str(respStatusCode))
if (respStatusCode >= 400):
    print("Response Header:")
    print(http.LastHeader)
    print("Failed.")
    sys.exit()

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

# {
#   "data": [
#     {
#       "id": "4150868000005376042",
#       "operation": "read",
#       "state": "COMPLETED",
#       "result": {
#         "page": 1,
#         "per_page": 200000,
#         "count": 96,
#         "download_url": "/crm/bulk/v2/read/4150868000005376042/result",
#         "more_records": false
#       },
#       "query": {
#         "fields": [
#           "Last_Name",
#           "Owner",
#           "Owner.last_name",
#           "Account_Name.Account_Name",
#           "Account_Name.Phone",
#           "Lead_Source",
#           "Created_Time"
#         ],
#         "module": "Contacts",
#         "criteria": {
#           "group": [
#             {
#               "api_name": "Lead_Source",
#               "comparator": "equal",
#               "value": "Advertisement"
#             },
#             {
#               "api_name": "Owner.last_name",
#               "comparator": "equal",
#               "value": "Boyle"
#             },
#             {
#               "api_name": "Account_Name.Phone",
#               "comparator": "contains",
#               "value": "5"
#             }
#           ],
#           "group_operator": "or"
#         },
#         "page": 1
#       },
#       "created_by": {
#         "id": "4150868000000225013",
#         "name": "Patricia Boyle"
#       },
#       "created_time": "2021-05-12T17:25:29+05:30",
#       "file_type": "csv"
#     }
#   ]
# }

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

i = 0
count_i = jResp.SizeOfArray("data")
while i < count_i :
    jResp.I = i
    id = jResp.StringOf("data[i].id")
    operation = jResp.StringOf("data[i].operation")
    state = jResp.StringOf("data[i].state")
    Page = jResp.IntOf("data[i].result.page")
    Per_page = jResp.IntOf("data[i].result.per_page")
    Count = jResp.IntOf("data[i].result.count")
    Download_url = jResp.StringOf("data[i].result.download_url")
    More_records = jResp.BoolOf("data[i].result.more_records")
    Module = jResp.StringOf("data[i].query.module")
    Group_operator = jResp.StringOf("data[i].query.criteria.group_operator")
    queryPage = jResp.IntOf("data[i].query.page")
    Id = jResp.StringOf("data[i].created_by.id")
    Name = jResp.StringOf("data[i].created_by.name")
    created_time = jResp.StringOf("data[i].created_time")
    file_type = jResp.StringOf("data[i].file_type")
    j = 0
    count_j = jResp.SizeOfArray("data[i].query.fields")
    while j < count_j :
        jResp.J = j
        strVal = jResp.StringOf("data[i].query.fields[j]")
        j = j + 1

    j = 0
    count_j = jResp.SizeOfArray("data[i].query.criteria.group")
    while j < count_j :
        jResp.J = j
        api_name = jResp.StringOf("data[i].query.criteria.group[j].api_name")
        comparator = jResp.StringOf("data[i].query.criteria.group[j].comparator")
        value = jResp.StringOf("data[i].query.criteria.group[j].value")
        j = j + 1

    i = i + 1

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: Bearer {{access-token}}"
https://www.zohoapis.com/crm/bulk/v2/read/{{job_id}}

Postman Collection Item JSON

{
  "name": "Get Bulk Read Job Details",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{access-token}}",
        "type": "text"
      }
    ],
    "url": {
      "raw": "https://www.zohoapis.com/crm/bulk/v2/read/{{job_id}}",
      "protocol": "https",
      "host": [
        "www",
        "zohoapis",
        "com"
      ],
      "path": [
        "crm",
        "bulk",
        "v2",
        "read",
        "{{job_id}}"
      ]
    },
    "description": "To get the details of a bulk read job performed previously.\n\n"
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://www.zohoapis.com/crm/bulk/v2/read/4150868000005376042",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "read",
            "4150868000005376042"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:55:44 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-12T17:36:34+05:30"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": [\n        {\n            \"id\": \"4150868000005376042\",\n            \"operation\": \"read\",\n            \"state\": \"COMPLETED\",\n            \"result\": {\n                \"page\": 1,\n                \"per_page\": 200000,\n                \"count\": 96,\n                \"download_url\": \"/crm/bulk/v2/read/4150868000005376042/result\",\n                \"more_records\": false\n            },\n            \"query\": {\n                \"fields\": [\n                    \"Last_Name\",\n                    \"Owner\",\n                    \"Owner.last_name\",\n                    \"Account_Name.Account_Name\",\n                    \"Account_Name.Phone\",\n                    \"Lead_Source\",\n                    \"Created_Time\"\n                ],\n                \"module\": \"Contacts\",\n                \"criteria\": {\n                    \"group\": [\n                        {\n                            \"api_name\": \"Lead_Source\",\n                            \"comparator\": \"equal\",\n                            \"value\": \"Advertisement\"\n                        },\n                        {\n                            \"api_name\": \"Owner.last_name\",\n                            \"comparator\": \"equal\",\n                            \"value\": \"Boyle\"\n                        },\n                        {\n                            \"api_name\": \"Account_Name.Phone\",\n                            \"comparator\": \"contains\",\n                            \"value\": \"5\"\n                        }\n                    ],\n                    \"group_operator\": \"or\"\n                },\n                \"page\": 1\n            },\n            \"created_by\": {\n                \"id\": \"4150868000000225013\",\n                \"name\": \"Patricia Boyle\"\n            },\n            \"created_time\": \"2021-05-12T17:25:29+05:30\",\n            \"file_type\": \"csv\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://www.zohoapis.com/crm/bulk/v2/rea/4150868000005376042",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "rea",
            "4150868000005376042"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:56:44 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": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://www.zohoapis.com/crm/bulk/v2/read/4150868000005376042",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "read",
            "4150868000005376042"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:57:14 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": "RESOURCE_NOT_FOUND",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://www.zohoapis.com/crm/bulk/v2/read/415086800000537604",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2",
            "read",
            "415086800000537604"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:57:44 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-12T17:36:34+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        \"resource\": \"415086800000537604\"\n    }\n}"
    }
  ]
}