Chilkat Online Tools

delphiDll / Zoho CRM REST APIs / Variables Data

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
api_name: PWideChar;
name: PWideChar;
description: PWideChar;
id: PWideChar;
v_type: PWideChar;
Api_name: PWideChar;
Id: PWideChar;
value: PWideChar;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

CkHttp_SetRequestHeader(http,'Authorization','{{authorization-token}}');

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://domain.com/crm/v2/settings/variables',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

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

// {
//   "variables": [
//     {
//       "api_name": "Test1",
//       "name": "Test1",
//       "description": "This denotes variable 3 description",
//       "id": "738964000002130239",
//       "type": "integer",
//       "variable_group": {
//         "api_name": "Group2",
//         "id": "738964000002058078"
//       },
//       "value": "33"
//     },
//     {
//       "api_name": "Test3",
//       "name": "Test3",
//       "description": "738964000002058078",
//       "id": "738964000002130243",
//       "type": "integer",
//       "variable_group": {
//         "api_name": "Group2",
//         "id": "738964000002058078"
//       },
//       "value": "100"
//     },
//     {
//       "api_name": "Variable100",
//       "name": "Variable100",
//       "description": "This denotes variable 3 description",
//       "id": "738964000002130237",
//       "type": "integer",
//       "variable_group": {
//         "api_name": "Group2",
//         "id": "738964000002058078"
//       },
//       "value": "33"
//     }
//   ]
// }

// 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 := CkJsonObject_SizeOfArray(jResp,'variables');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    api_name := CkJsonObject__stringOf(jResp,'variables[i].api_name');
    name := CkJsonObject__stringOf(jResp,'variables[i].name');
    description := CkJsonObject__stringOf(jResp,'variables[i].description');
    id := CkJsonObject__stringOf(jResp,'variables[i].id');
    v_type := CkJsonObject__stringOf(jResp,'variables[i].type');
    Api_name := CkJsonObject__stringOf(jResp,'variables[i].variable_group.api_name');
    Id := CkJsonObject__stringOf(jResp,'variables[i].variable_group.id');
    value := CkJsonObject__stringOf(jResp,'variables[i].value');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
https://domain.com/crm/v2/settings/variables

Postman Collection Item JSON

{
  "name": "Variables Data",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": "{{authorization-token}}"
      }
    ],
    "url": {
      "raw": "{{api-domain}}/crm/v2/settings/variables",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "settings",
        "variables"
      ]
    },
    "description": "To retrieve all the available variables through an API request."
  },
  "response": [
    {
      "name": "P1: group",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variables?group=Group2",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variables"
          ],
          "query": [
            {
              "key": "group",
              "value": "Group2"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:15:09 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "638"
        },
        {
          "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-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-12T07:15:06+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"variables\": [\n        {\n            \"api_name\": \"Test1\",\n            \"name\": \"Test1\",\n            \"description\": \"This denotes variable 3 description\",\n            \"id\": \"738964000002130239\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"33\"\n        },\n        {\n            \"api_name\": \"Test3\",\n            \"name\": \"Test3\",\n            \"description\": \"738964000002058078\",\n            \"id\": \"738964000002130243\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"100\"\n        },\n        {\n            \"api_name\": \"Variable100\",\n            \"name\": \"Variable100\",\n            \"description\": \"This denotes variable 3 description\",\n            \"id\": \"738964000002130237\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"33\"\n        }\n    ]\n}"
    },
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variables",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variables"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 16:14:49 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "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-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-11T16:58:15+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"variables\": [\n        {\n            \"api_name\": \"Test2\",\n            \"name\": \"Variable100\",\n            \"description\": \"This denotes variable 100 description\",\n            \"id\": \"738964000002130241\",\n            \"type\": \"text\",\n            \"variable_group\": {\n                \"api_name\": \"General\",\n                \"id\": \"738964000002130233\"\n            },\n            \"value\": \"Hello\"\n        },\n        {\n            \"api_name\": \"Variable101\",\n            \"name\": \"Variable101\",\n            \"description\": \"This denotes variable 4 description\",\n            \"id\": \"738964000002130235\",\n            \"type\": \"text\",\n            \"variable_group\": {\n                \"api_name\": \"General\",\n                \"id\": \"738964000002130233\"\n            },\n            \"value\": \"Hello\"\n        },\n        {\n            \"api_name\": \"Test1\",\n            \"name\": \"Test1\",\n            \"description\": \"This denotes variable 3 description\",\n            \"id\": \"738964000002130239\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"33\"\n        },\n        {\n            \"api_name\": \"Test3\",\n            \"name\": \"Test3\",\n            \"description\": \"738964000002058078\",\n            \"id\": \"738964000002130243\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"100\"\n        },\n        {\n            \"api_name\": \"Variable100\",\n            \"name\": \"Variable100\",\n            \"description\": \"This denotes variable 3 description\",\n            \"id\": \"738964000002130237\",\n            \"type\": \"integer\",\n            \"variable_group\": {\n                \"api_name\": \"Group2\",\n                \"id\": \"738964000002058078\"\n            },\n            \"value\": \"33\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variable",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variable"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:15:46 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "131"
        },
        {
          "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-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-12T07:15:06+00:00"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        }
      ],
      "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": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variables",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variables"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:16:10 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": [
          {
            "key": "Authorization",
            "value": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variables",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variables"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:16:30 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": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "{{authorization-token}}"
          }
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/variables",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "variables"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 08:30:19 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}"
    }
  ]
}