Chilkat Online Tools

unicodeC / Salesforce Platform APIs / Get List View Records and Metadata API Name

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *fieldApiName;
    const wchar_t *lookupId;
    BOOL sortable;
    BOOL isAscending;
    BOOL cloneable;
    BOOL createable;
    BOOL deletable;
    const wchar_t *eTag;
    const wchar_t *filterLogicString;
    const wchar_t *label;
    const wchar_t *Id;
    const wchar_t *ListViewApiName;
    const wchar_t *ObjectApiName;
    const wchar_t *v_Type;
    BOOL updateable;
    int Site;
    int ColumnWidthsType;
    int BillingCountry;
    int Owner_Alias;
    int Phone;
    int Name;
    BOOL ColumnWrapSite;
    BOOL ColumnWrapType;
    BOOL ColumnWrapBillingCountry;
    BOOL ColumnWrapOwner_Alias;
    BOOL ColumnWrapPhone;
    BOOL ColumnWrapName;
    const wchar_t *visibility;
    BOOL visibilityEditable;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://domain.com/services/data/v{{version}}/ui-api/list-info/:SOBJECT_API_NAME/:LIST_VIEW_API_NAME",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

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

    // {
    //   "cloneable": true,
    //   "createable": true,
    //   "deletable": true,
    //   "displayColumns": [
    //     {
    //       "fieldApiName": "Name",
    //       "label": "Account Name",
    //       "lookupId": "Id",
    //       "sortable": true
    //     },
    //     {
    //       "fieldApiName": "Site",
    //       "label": "Account Site",
    //       "lookupId": null,
    //       "sortable": true
    //     },
    //     {
    //       "fieldApiName": "Phone",
    //       "label": "Phone",
    //       "lookupId": null,
    //       "sortable": true
    //     },
    //     {
    //       "fieldApiName": "Type",
    //       "label": "Type",
    //       "lookupId": null,
    //       "sortable": true
    //     },
    //     {
    //       "fieldApiName": "BillingCountry",
    //       "label": "Billing Country",
    //       "lookupId": null,
    //       "sortable": true
    //     },
    //     {
    //       "fieldApiName": "Owner.Alias",
    //       "label": "Account Owner Alias",
    //       "lookupId": "Owner.Id",
    //       "sortable": true
    //     }
    //   ],
    //   "eTag": "55ebdd0de6c2f1e17f63bf4581d64f76",
    //   "filterLogicString": null,
    //   "filteredByInfo": [
    //   ],
    //   "label": "All Accounts",
    //   "listReference": {
    //     "id": "00B58000002ssinEAA",
    //     "listViewApiName": "AllAccounts",
    //     "objectApiName": "Account",
    //     "type": "listView"
    //   },
    //   "objectApiNames": [
    //   ],
    //   "orderedByInfo": [
    //     {
    //       "fieldApiName": "BillingCountry",
    //       "isAscending": false,
    //       "label": "Billing Country"
    //     }
    //   ],
    //   "updateable": true,
    //   "userPreferences": {
    //     "columnWidths": {
    //       "Site": -1,
    //       "Type": -1,
    //       "BillingCountry": -1,
    //       "Owner.Alias": -1,
    //       "Phone": -1,
    //       "Name": -1
    //     },
    //     "columnWrap": {
    //       "Site": false,
    //       "Type": false,
    //       "BillingCountry": false,
    //       "Owner.Alias": false,
    //       "Phone": false,
    //       "Name": false
    //     }
    //   },
    //   "visibility": "Public",
    //   "visibilityEditable": true
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    cloneable = CkJsonObjectW_BoolOf(jResp,L"cloneable");
    createable = CkJsonObjectW_BoolOf(jResp,L"createable");
    deletable = CkJsonObjectW_BoolOf(jResp,L"deletable");
    eTag = CkJsonObjectW_stringOf(jResp,L"eTag");
    filterLogicString = CkJsonObjectW_stringOf(jResp,L"filterLogicString");
    label = CkJsonObjectW_stringOf(jResp,L"label");
    Id = CkJsonObjectW_stringOf(jResp,L"listReference.id");
    ListViewApiName = CkJsonObjectW_stringOf(jResp,L"listReference.listViewApiName");
    ObjectApiName = CkJsonObjectW_stringOf(jResp,L"listReference.objectApiName");
    v_Type = CkJsonObjectW_stringOf(jResp,L"listReference.type");
    updateable = CkJsonObjectW_BoolOf(jResp,L"updateable");
    Site = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.Site");
    ColumnWidthsType = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.Type");
    BillingCountry = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.BillingCountry");
    Owner_Alias = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.\"Owner.Alias\"");
    Phone = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.Phone");
    Name = CkJsonObjectW_IntOf(jResp,L"userPreferences.columnWidths.Name");
    ColumnWrapSite = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.Site");
    ColumnWrapType = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.Type");
    ColumnWrapBillingCountry = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.BillingCountry");
    ColumnWrapOwner_Alias = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.\"Owner.Alias\"");
    ColumnWrapPhone = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.Phone");
    ColumnWrapName = CkJsonObjectW_BoolOf(jResp,L"userPreferences.columnWrap.Name");
    visibility = CkJsonObjectW_stringOf(jResp,L"visibility");
    visibilityEditable = CkJsonObjectW_BoolOf(jResp,L"visibilityEditable");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"displayColumns");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        fieldApiName = CkJsonObjectW_stringOf(jResp,L"displayColumns[i].fieldApiName");
        label = CkJsonObjectW_stringOf(jResp,L"displayColumns[i].label");
        lookupId = CkJsonObjectW_stringOf(jResp,L"displayColumns[i].lookupId");
        sortable = CkJsonObjectW_BoolOf(jResp,L"displayColumns[i].sortable");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"filteredByInfo");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"objectApiNames");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"orderedByInfo");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        fieldApiName = CkJsonObjectW_stringOf(jResp,L"orderedByInfo[i].fieldApiName");
        isAscending = CkJsonObjectW_BoolOf(jResp,L"orderedByInfo[i].isAscending");
        label = CkJsonObjectW_stringOf(jResp,L"orderedByInfo[i].label");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/ui-api/list-info/:SOBJECT_API_NAME/:LIST_VIEW_API_NAME

Postman Collection Item JSON

{
  "name": "Get List View Records and Metadata API Name",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/list-info/:SOBJECT_API_NAME/:LIST_VIEW_API_NAME",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "ui-api",
        "list-info",
        ":SOBJECT_API_NAME",
        ":LIST_VIEW_API_NAME"
      ],
      "variable": [
        {
          "key": "SOBJECT_API_NAME",
          "value": "",
          "description": "Object API name"
        },
        {
          "key": "LIST_VIEW_API_NAME",
          "value": "",
          "description": "List view API name"
        }
      ]
    },
    "description": "Returns record data and metadata for a list view."
  },
  "response": [
    {
      "name": "Get List View Records and Metadata API Name",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/list-info/:SOBJECT_API_NAME/:LIST_VIEW_API_NAME",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "ui-api",
            "list-info",
            ":SOBJECT_API_NAME",
            ":LIST_VIEW_API_NAME"
          ],
          "variable": [
            {
              "key": "SOBJECT_API_NAME",
              "value": "Account",
              "description": "Object API name"
            },
            {
              "key": "LIST_VIEW_API_NAME",
              "value": "AllAccounts",
              "description": "List view API name"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Fri, 06 Oct 2023 09:58:32 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "ETag",
          "value": "\"55ebdd0de6c2f1e17f63bf4581d64f76--gzip\""
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"cloneable\": true,\n    \"createable\": true,\n    \"deletable\": true,\n    \"displayColumns\": [\n        {\n            \"fieldApiName\": \"Name\",\n            \"label\": \"Account Name\",\n            \"lookupId\": \"Id\",\n            \"sortable\": true\n        },\n        {\n            \"fieldApiName\": \"Site\",\n            \"label\": \"Account Site\",\n            \"lookupId\": null,\n            \"sortable\": true\n        },\n        {\n            \"fieldApiName\": \"Phone\",\n            \"label\": \"Phone\",\n            \"lookupId\": null,\n            \"sortable\": true\n        },\n        {\n            \"fieldApiName\": \"Type\",\n            \"label\": \"Type\",\n            \"lookupId\": null,\n            \"sortable\": true\n        },\n        {\n            \"fieldApiName\": \"BillingCountry\",\n            \"label\": \"Billing Country\",\n            \"lookupId\": null,\n            \"sortable\": true\n        },\n        {\n            \"fieldApiName\": \"Owner.Alias\",\n            \"label\": \"Account Owner Alias\",\n            \"lookupId\": \"Owner.Id\",\n            \"sortable\": true\n        }\n    ],\n    \"eTag\": \"55ebdd0de6c2f1e17f63bf4581d64f76\",\n    \"filterLogicString\": null,\n    \"filteredByInfo\": [],\n    \"label\": \"All Accounts\",\n    \"listReference\": {\n        \"id\": \"00B58000002ssinEAA\",\n        \"listViewApiName\": \"AllAccounts\",\n        \"objectApiName\": \"Account\",\n        \"type\": \"listView\"\n    },\n    \"objectApiNames\": [],\n    \"orderedByInfo\": [\n        {\n            \"fieldApiName\": \"BillingCountry\",\n            \"isAscending\": false,\n            \"label\": \"Billing Country\"\n        }\n    ],\n    \"updateable\": true,\n    \"userPreferences\": {\n        \"columnWidths\": {\n            \"Site\": -1,\n            \"Type\": -1,\n            \"BillingCountry\": -1,\n            \"Owner.Alias\": -1,\n            \"Phone\": -1,\n            \"Name\": -1\n        },\n        \"columnWrap\": {\n            \"Site\": false,\n            \"Type\": false,\n            \"BillingCountry\": false,\n            \"Owner.Alias\": false,\n            \"Phone\": false,\n            \"Name\": false\n        }\n    },\n    \"visibility\": \"Public\",\n    \"visibilityEditable\": true\n}"
    }
  ]
}