Chilkat Online Tools

SQL Server / Zoho CRM REST APIs / 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://domain.com/crm/bulk/v2.1/write/{{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)

    -- {
    --   "status": "COMPLETED",
    --   "character_encoding": "UTF-8",
    --   "resource": [
    --     {
    --       "status": "COMPLETED",
    --       "type": "data",
    --       "module": {
    --         "id": "4150868000000002175",
    --         "api_name": "Leads"
    --       },
    --       "field_mappings": [
    --         {
    --           "api_name": "Owner",
    --           "index": 2,
    --           "format": null,
    --           "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": "Mobile",
    --           "index": 1,
    --           "format": null,
    --           "find_by": null,
    --           "module": null,
    --           "default_value": null
    --         }
    --       ],
    --       "file": {
    --         "status": "COMPLETED",
    --         "name": "Fil2.csv",
    --         "added_count": 9,
    --         "skipped_count": 2,
    --         "updated_count": 0,
    --         "total_count": 11
    --       },
    --       "code": "COMPLETED"
    --     }
    --   ],
    --   "id": "4150868000005350003",
    --   "callback": {
    --     "url": "https://www.zoho.com/",
    --     "method": "post"
    --   },
    --   "result": {
    --     "download_url": "https://download-accl.zoho.com/v2/crm/694902309/bulk-write/4150868000005350003/4150868000005350003.zip"
    --   },
    --   "created_by": {
    --     "id": "4150868000000225013",
    --     "name": "Patricia Boyle"
    --   },
    --   "ignore_empty": true,
    --   "operation": "insert",
    --   "created_time": "2021-05-11T12:38:29+05:30"
    -- }

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

    DECLARE @v_type nvarchar(4000)

    DECLARE @moduleId nvarchar(4000)

    DECLARE @Api_name nvarchar(4000)

    DECLARE @Status nvarchar(4000)

    DECLARE @fileName nvarchar(4000)

    DECLARE @Added_count int

    DECLARE @Skipped_count int

    DECLARE @Updated_count int

    DECLARE @Total_count int

    DECLARE @code nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @api_name nvarchar(4000)

    DECLARE @index int

    DECLARE @format nvarchar(4000)

    DECLARE @find_by nvarchar(4000)

    DECLARE @module nvarchar(4000)

    DECLARE @default_value nvarchar(4000)

    DECLARE @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @character_encoding nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @character_encoding OUT, 'character_encoding'
    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @v_Url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Url OUT, 'callback.url'
    DECLARE @Method nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Method OUT, 'callback.method'
    DECLARE @Download_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Download_url OUT, 'result.download_url'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'created_by.id'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'created_by.name'
    DECLARE @ignore_empty int
    EXEC sp_OAMethod @jResp, 'BoolOf', @ignore_empty OUT, 'ignore_empty'
    DECLARE @operation nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @operation OUT, 'operation'
    DECLARE @created_time nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @created_time OUT, 'created_time'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'resource'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'resource[i].status'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'resource[i].type'
        EXEC sp_OAMethod @jResp, 'StringOf', @moduleId OUT, 'resource[i].module.id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Api_name OUT, 'resource[i].module.api_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'resource[i].file.status'
        EXEC sp_OAMethod @jResp, 'StringOf', @fileName OUT, 'resource[i].file.name'
        EXEC sp_OAMethod @jResp, 'IntOf', @Added_count OUT, 'resource[i].file.added_count'
        EXEC sp_OAMethod @jResp, 'IntOf', @Skipped_count OUT, 'resource[i].file.skipped_count'
        EXEC sp_OAMethod @jResp, 'IntOf', @Updated_count OUT, 'resource[i].file.updated_count'
        EXEC sp_OAMethod @jResp, 'IntOf', @Total_count OUT, 'resource[i].file.total_count'
        EXEC sp_OAMethod @jResp, 'StringOf', @code OUT, 'resource[i].code'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'resource[i].field_mappings'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @api_name OUT, 'resource[i].field_mappings[j].api_name'
            EXEC sp_OAMethod @jResp, 'IntOf', @index OUT, 'resource[i].field_mappings[j].index'
            EXEC sp_OAMethod @jResp, 'StringOf', @format OUT, 'resource[i].field_mappings[j].format'
            EXEC sp_OAMethod @jResp, 'StringOf', @find_by OUT, 'resource[i].field_mappings[j].find_by'
            EXEC sp_OAMethod @jResp, 'StringOf', @module OUT, 'resource[i].field_mappings[j].module'
            EXEC sp_OAMethod @jResp, 'StringOf', @default_value OUT, 'resource[i].field_mappings[j].default_value'
            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>"
https://domain.com/crm/bulk/v2.1/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.1/write/{{job_id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "bulk",
        "v2.1",
        "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.1/write/4150868000005350003",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "write",
            "4150868000005350003"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 07:21:37 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-11T12:57:31+05:30"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"status\": \"COMPLETED\",\n    \"character_encoding\": \"UTF-8\",\n    \"resource\": [\n        {\n            \"status\": \"COMPLETED\",\n            \"type\": \"data\",\n            \"module\": {\n                \"id\": \"4150868000000002175\",\n                \"api_name\": \"Leads\"\n            },\n            \"field_mappings\": [\n                {\n                    \"api_name\": \"Owner\",\n                    \"index\": 2,\n                    \"format\": null,\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\": \"Mobile\",\n                    \"index\": 1,\n                    \"format\": null,\n                    \"find_by\": null,\n                    \"module\": null,\n                    \"default_value\": null\n                }\n            ],\n            \"file\": {\n                \"status\": \"COMPLETED\",\n                \"name\": \"Fil2.csv\",\n                \"added_count\": 9,\n                \"skipped_count\": 2,\n                \"updated_count\": 0,\n                \"total_count\": 11\n            },\n            \"code\": \"COMPLETED\"\n        }\n    ],\n    \"id\": \"4150868000005350003\",\n    \"callback\": {\n        \"url\": \"https://www.zoho.com/\",\n        \"method\": \"post\"\n    },\n    \"result\": {\n        \"download_url\": \"https://download-accl.zoho.com/v2/crm/694902309/bulk-write/4150868000005350003/4150868000005350003.zip\"\n    },\n    \"created_by\": {\n        \"id\": \"4150868000000225013\",\n        \"name\": \"Patricia Boyle\"\n    },\n    \"ignore_empty\": true,\n    \"operation\": \"insert\",\n    \"created_time\": \"2021-05-11T12:38:29+05:30\"\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/writ/4150868000005350003",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "writ",
            "4150868000005350003"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 07:29:26 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": "PUT",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/write/4150868000005350003",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "write",
            "4150868000005350003"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 07:29:51 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.1/write/4150868000005350003",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "write",
            "4150868000005350003"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 07:30:07 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.1/write/415086800000535000",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "write",
            "415086800000535000"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 07:30:33 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-11T14:00:30+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}"
    },
    {
      "name": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/write/4150868000005350003",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "write",
            "4150868000005350003"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 08:24:50 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}"
    }
  ]
}