Chilkat Online Tools

SQL Server / Zoho CRM REST APIs / Get Bulk Read Job Details

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Adds the "Authorization: Bearer {{access-token}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{access-token}}'

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://www.zohoapis.com/crm/bulk/v2.1/read/{{job_id}}', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    -- {
    --   "data": [
    --     {
    --       "id": "4150868000005277059",
    --       "operation": "read",
    --       "state": "COMPLETED",
    --       "result": {
    --         "page": 1,
    --         "per_page": 200000,
    --         "count": 0,
    --         "download_url": "/crm/bulk/v2.1/read/4150868000005277059/result",
    --         "more_records": false
    --       },
    --       "query": {
    --         "fields": [
    --           "Last_Name",
    --           "Owner",
    --           "Owner.last_name",
    --           "$converted",
    --           "Lead_Source",
    --           "Lead_Status",
    --           "Company",
    --           "Email",
    --           "Mobile",
    --           "Created_Time"
    --         ],
    --         "module": {
    --           "id": "4150868000000002175",
    --           "api_name": "Leads"
    --         },
    --         "criteria": {
    --           "group": [
    --             {
    --               "field": {
    --                 "id": null,
    --                 "api_name": "$converted"
    --               },
    --               "comparator": "equal",
    --               "value": false
    --             },
    --             {
    --               "group": [
    --                 {
    --                   "field": {
    --                     "id": "4150868000000002595",
    --                     "api_name": "Last_Name"
    --                   },
    --                   "comparator": "equal",
    --                   "value": "Patricia"
    --                 },
    --                 {
    --                   "field": {
    --                     "id": "4150868000000002599",
    --                     "api_name": "Email"
    --                   },
    --                   "comparator": "equal",
    --                   "value": "patricia.b@zylker.com"
    --                 }
    --               ],
    --               "group_operator": "and"
    --             }
    --           ],
    --           "group_operator": "and"
    --         },
    --         "page": 1,
    --         "cvid": "4150868000000087501"
    --       },
    --       "created_by": {
    --         "id": "4150868000000225013",
    --         "name": "Patricia Boyle"
    --       },
    --       "created_time": "2021-05-03T18:32:25+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

    DECLARE @id nvarchar(4000)

    DECLARE @operation nvarchar(4000)

    DECLARE @state nvarchar(4000)

    DECLARE @Page int

    DECLARE @Per_page int

    DECLARE @Count int

    DECLARE @Download_url nvarchar(4000)

    DECLARE @More_records int

    DECLARE @Id nvarchar(4000)

    DECLARE @Api_name nvarchar(4000)

    DECLARE @Group_operator nvarchar(4000)

    DECLARE @queryPage int

    DECLARE @Cvid nvarchar(4000)

    DECLARE @created_byId nvarchar(4000)

    DECLARE @Name nvarchar(4000)

    DECLARE @created_time nvarchar(4000)

    DECLARE @file_type nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @strVal nvarchar(4000)

    DECLARE @fieldId nvarchar(4000)

    DECLARE @fieldApi_name nvarchar(4000)

    DECLARE @comparator nvarchar(4000)

    DECLARE @value int

    DECLARE @group_operator nvarchar(4000)

    DECLARE @k int

    DECLARE @count_k int

    DECLARE @value_str nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'data[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @operation OUT, 'data[i].operation'
        EXEC sp_OAMethod @jResp, 'StringOf', @state OUT, 'data[i].state'
        EXEC sp_OAMethod @jResp, 'IntOf', @Page OUT, 'data[i].result.page'
        EXEC sp_OAMethod @jResp, 'IntOf', @Per_page OUT, 'data[i].result.per_page'
        EXEC sp_OAMethod @jResp, 'IntOf', @Count OUT, 'data[i].result.count'
        EXEC sp_OAMethod @jResp, 'StringOf', @Download_url OUT, 'data[i].result.download_url'
        EXEC sp_OAMethod @jResp, 'BoolOf', @More_records OUT, 'data[i].result.more_records'
        EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data[i].query.module.id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Api_name OUT, 'data[i].query.module.api_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @Group_operator OUT, 'data[i].query.criteria.group_operator'
        EXEC sp_OAMethod @jResp, 'IntOf', @queryPage OUT, 'data[i].query.page'
        EXEC sp_OAMethod @jResp, 'StringOf', @Cvid OUT, 'data[i].query.cvid'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_byId OUT, 'data[i].created_by.id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data[i].created_by.name'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_time OUT, 'data[i].created_time'
        EXEC sp_OAMethod @jResp, 'StringOf', @file_type OUT, 'data[i].file_type'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'data[i].query.fields'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'data[i].query.fields[j]'
            SELECT @j = @j + 1
          END
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'data[i].query.criteria.group'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @fieldId OUT, 'data[i].query.criteria.group[j].field.id'
            EXEC sp_OAMethod @jResp, 'StringOf', @fieldApi_name OUT, 'data[i].query.criteria.group[j].field.api_name'
            EXEC sp_OAMethod @jResp, 'StringOf', @comparator OUT, 'data[i].query.criteria.group[j].comparator'
            EXEC sp_OAMethod @jResp, 'BoolOf', @value OUT, 'data[i].query.criteria.group[j].value'
            EXEC sp_OAMethod @jResp, 'StringOf', @group_operator OUT, 'data[i].query.criteria.group[j].group_operator'
            SELECT @k = 0
            EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_k OUT, 'data[i].query.criteria.group[j].group'
            WHILE @k < @count_k
              BEGIN
                EXEC sp_OASetProperty @jResp, 'K', @k
                EXEC sp_OAMethod @jResp, 'StringOf', @fieldId OUT, 'data[i].query.criteria.group[j].group[k].field.id'
                EXEC sp_OAMethod @jResp, 'StringOf', @fieldApi_name OUT, 'data[i].query.criteria.group[j].group[k].field.api_name'
                EXEC sp_OAMethod @jResp, 'StringOf', @comparator OUT, 'data[i].query.criteria.group[j].group[k].comparator'
                EXEC sp_OAMethod @jResp, 'StringOf', @value_str OUT, 'data[i].query.criteria.group[j].group[k].value'
                SELECT @k = @k + 1
              END
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: Bearer {{access-token}}"
https://www.zohoapis.com/crm/bulk/v2.1/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.1/read/{{job_id}}",
      "protocol": "https",
      "host": [
        "www",
        "zohoapis",
        "com"
      ],
      "path": [
        "crm",
        "bulk",
        "v2.1",
        "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.1/read/4150868000005277059",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read",
            "4150868000005277059"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 11:25:24 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-04T17:55:19+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\": \"4150868000005277059\",\n            \"operation\": \"read\",\n            \"state\": \"COMPLETED\",\n            \"result\": {\n                \"page\": 1,\n                \"per_page\": 200000,\n                \"count\": 0,\n                \"download_url\": \"/crm/bulk/v2.1/read/4150868000005277059/result\",\n                \"more_records\": false\n            },\n            \"query\": {\n                \"fields\": [\n                    \"Last_Name\",\n                    \"Owner\",\n                    \"Owner.last_name\",\n                    \"$converted\",\n                    \"Lead_Source\",\n                    \"Lead_Status\",\n                    \"Company\",\n                    \"Email\",\n                    \"Mobile\",\n                    \"Created_Time\"\n                ],\n                \"module\": {\n                    \"id\": \"4150868000000002175\",\n                    \"api_name\": \"Leads\"\n                },\n                \"criteria\": {\n                    \"group\": [\n                        {\n                            \"field\": {\n                                \"id\": null,\n                                \"api_name\": \"$converted\"\n                            },\n                            \"comparator\": \"equal\",\n                            \"value\": false\n                        },\n                        {\n                            \"group\": [\n                                {\n                                    \"field\": {\n                                        \"id\": \"4150868000000002595\",\n                                        \"api_name\": \"Last_Name\"\n                                    },\n                                    \"comparator\": \"equal\",\n                                    \"value\": \"Patricia\"\n                                },\n                                {\n                                    \"field\": {\n                                        \"id\": \"4150868000000002599\",\n                                        \"api_name\": \"Email\"\n                                    },\n                                    \"comparator\": \"equal\",\n                                    \"value\": \"patricia.b@zylker.com\"\n                                }\n                            ],\n                            \"group_operator\": \"and\"\n                        }\n                    ],\n                    \"group_operator\": \"and\"\n                },\n                \"page\": 1,\n                \"cvid\": \"4150868000000087501\"\n            },\n            \"created_by\": {\n                \"id\": \"4150868000000225013\",\n                \"name\": \"Patricia Boyle\"\n            },\n            \"created_time\": \"2021-05-03T18:32:25+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.1/read4150868000005277059",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read4150868000005277059"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 11:26:53 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": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://www.zohoapis.com/crm/bulk/v2.1/read/4150868000005277059",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read",
            "4150868000005277059"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 11:27:28 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.1/read/415086800000527705",
          "protocol": "https",
          "host": [
            "www",
            "zohoapis",
            "com"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read",
            "415086800000527705"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 11:27:58 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-04T17:55:19+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\": \"415086800000527705\"\n    }\n}"
    },
    {
      "name": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/read/4150868000005277059",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read",
            "4150868000005277059"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 13:36:09 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "113"
        },
        {
          "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\": \"OAUTH_SCOPE_MISMATCH\",\n    \"details\": {},\n    \"message\": \"invalid oauth scope to access this URL\",\n    \"status\": \"error\"\n}"
    }
  ]
}