Chilkat Online Tools

Foxpro / Zoho CRM REST APIs / Create Bulk Read Job (ICS)

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcStatus
LOCAL lcCode
LOCAL lcMessage
LOCAL lcId
LOCAL lcOperation
LOCAL lcState
LOCAL lcCreated_byId
LOCAL lcName
LOCAL lcCreated_time
LOCAL i
LOCAL lnCount_i

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* Use this online tool to generate code from sample JSON: Generate Code to Create JSON

* The following JSON is sent in the request body.

* {
*   "callback": {
*     "url": "https://www.example.com/callback",
*     "method": "post"
*   },
*   "query": {
*     "module": "Contacts",
*     "fields": [
*       "Last_Name",
*       "Owner",
*       "Owner.last_name",
*       "Account_Name.Account_Name",
*       "Account_Name.Phone",
*       "Lead_Source",
*       "Created_Time"
*     ],
*     "criteria": {
*       "group_operator": "or",
*       "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"
*         }
*       ]
*     },
*     "page": 1
*   }
* }

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("callback.url","https://www.example.com/callback")
loJson.UpdateString("callback.method","post")
loJson.UpdateString("query.module","Contacts")
loJson.UpdateString("query.fields[0]","Last_Name")
loJson.UpdateString("query.fields[1]","Owner")
loJson.UpdateString("query.fields[2]","Owner.last_name")
loJson.UpdateString("query.fields[3]","Account_Name.Account_Name")
loJson.UpdateString("query.fields[4]","Account_Name.Phone")
loJson.UpdateString("query.fields[5]","Lead_Source")
loJson.UpdateString("query.fields[6]","Created_Time")
loJson.UpdateString("query.criteria.group_operator","or")
loJson.UpdateString("query.criteria.group[0].api_name","Lead_Source")
loJson.UpdateString("query.criteria.group[0].comparator","equal")
loJson.UpdateString("query.criteria.group[0].value","Advertisement")
loJson.UpdateString("query.criteria.group[1].api_name","Owner.last_name")
loJson.UpdateString("query.criteria.group[1].comparator","equal")
loJson.UpdateString("query.criteria.group[1].value","Boyle")
loJson.UpdateString("query.criteria.group[2].api_name","Account_Name.Phone")
loJson.UpdateString("query.criteria.group[2].comparator","contains")
loJson.UpdateString("query.criteria.group[2].value","5")
loJson.UpdateInt("query.page",1)

* Adds the "Authorization: Bearer {{access-token}}" header.
loHttp.AuthToken = "{{access-token}}"
loHttp.SetRequestHeader("Content-Type","application/json")

loResp = loHttp.PostJson3("https://domain.com/crm/bulk/v2.1/read","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJson
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

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

* {
*   "data": [
*     {
*       "status": "success",
*       "code": "ADDED_SUCCESSFULLY",
*       "message": "Added successfully.",
*       "details": {
*         "id": "4150868000005277059",
*         "operation": "read",
*         "state": "ADDED",
*         "created_by": {
*           "id": "4150868000000225013",
*           "name": "Patricia Boyle"
*         },
*         "created_time": "2021-05-03T18:32:25+05:30"
*       }
*     }
*   ],
*   "info": {}
* }

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

i = 0
lnCount_i = loJResp.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStatus = loJResp.StringOf("data[i].status")
    lcCode = loJResp.StringOf("data[i].code")
    lcMessage = loJResp.StringOf("data[i].message")
    lcId = loJResp.StringOf("data[i].details.id")
    lcOperation = loJResp.StringOf("data[i].details.operation")
    lcState = loJResp.StringOf("data[i].details.state")
    lcCreated_byId = loJResp.StringOf("data[i].details.created_by.id")
    lcName = loJResp.StringOf("data[i].details.created_by.name")
    lcCreated_time = loJResp.StringOf("data[i].details.created_time")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: Bearer {{access-token}}"
	-H "Content-Type: application/json"
	-d '{
  "callback": {
    "url": "https://www.example.com/callback",
    "method": "post"
  },
  "query": {
    "module": "Contacts",
    "fields": [
      "Last_Name",
      "Owner",
      "Owner.last_name",
      "Account_Name.Account_Name",
      "Account_Name.Phone",
      "Lead_Source",
      "Created_Time"
    ],
    "criteria": {
      "group_operator": "or",
      "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"
        }
      ]
    },
    "page": 1
  }
}'
https://domain.com/crm/bulk/v2.1/read

Postman Collection Item JSON

{
  "name": "Create Bulk Read Job (ICS)",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "warning": "This is a duplicate header and will be overridden by the Authorization header generated by Postman.",
        "key": "Authorization",
        "value": "Bearer {{access-token}}",
        "type": "text"
      },
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"callback\": {\n    \"url\": \"https://www.example.com/callback\",\n    \"method\": \"post\"\n  },\n  \"query\": {\n    \"module\": \"Contacts\",\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    \"criteria\": {\n      \"group_operator\": \"or\",\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    },\n    \"page\": 1\n  }\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/bulk/v2.1/read",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "bulk",
        "v2.1",
        "read"
      ]
    },
    "description": "To create a bulk read job to export records."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "warning": "This is a duplicate header and will be overridden by the Authorization header generated by Postman.",
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"callback\": {\n        \"url\": \"https://www.example.com/callback\",\n        \"method\": \"post\"\n    },\n    \"query\": {\n        \"module\": {\n            \"api_name\": \"Leads\"\n        },\n        \"cvid\": \"4150868000000087501\",\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        \"criteria\": {\n            \"group\": [\n                {\n                    \"field\": {\n                        \"api_name\": \"Last_Name\"\n                    },\n                    \"comparator\": \"equal\",\n                    \"value\": \"Patricia\"\n                },\n                {\n                    \"field\": {\n                        \"api_name\": \"Email\"\n                    },\n                    \"comparator\": \"equal\",\n                    \"value\": \"patricia.b@zylker.com\"\n                }\n            ],\n            \"group_operator\": \"and\"\n        }\n    }\n}"
        },
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/read",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 03 May 2021 13:02:25 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-03T19:27:14+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            \"status\": \"success\",\n            \"code\": \"ADDED_SUCCESSFULLY\",\n            \"message\": \"Added successfully.\",\n            \"details\": {\n                \"id\": \"4150868000005277059\",\n                \"operation\": \"read\",\n                \"state\": \"ADDED\",\n                \"created_by\": {\n                    \"id\": \"4150868000000225013\",\n                    \"name\": \"Patricia Boyle\"\n                },\n                \"created_time\": \"2021-05-03T18:32:25+05:30\"\n            }\n        }\n    ],\n    \"info\": {}\n}"
    },
    {
      "name": "MEDIA_TYPE_NOT_SUPPORTED",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"callback\": {\n    \"url\": \"https://www.example.com/callback\",\n    \"method\": \"post\"\n  },\n  \"query\": {\n    \"module\": \"Contacts\",\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    \"criteria\": {\n      \"group_operator\": \"or\",\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    },\n    \"page\": 1\n  }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/read",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read"
          ]
        }
      },
      "status": "Unsupported Media Type",
      "code": 415,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 03 May 2021 12:59: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-03T19:27:14+05:30"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"status\": \"error\",\n    \"code\": \"MEDIA_TYPE_NOT_SUPPORTED\",\n    \"message\": \"Media type is not supported.\",\n    \"details\": [\n        \"application/json\"\n    ]\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access-token}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"callback\": {\n    \"url\": \"https://www.example.com/callback\",\n    \"method\": \"post\"\n  },\n  \"query\": {\n    \"module\": \"Contacts\",\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    \"criteria\": {\n      \"group_operator\": \"or\",\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    },\n    \"page\": 1\n  }\n}"
        },
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/rea",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "rea"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 03 May 2021 13:00:02 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"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"callback\": {\n    \"url\": \"https://www.example.com/callback\",\n    \"method\": \"post\"\n  },\n  \"query\": {\n    \"module\": \"Contacts\",\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    \"criteria\": {\n      \"group_operator\": \"or\",\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    },\n    \"page\": 1\n  }\n}"
        },
        "url": {
          "raw": "{{api-domain}}/crm/bulk/v2.1/read",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "bulk",
            "v2.1",
            "read"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 03 May 2021 13:00: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}"
    }
  ]
}