Chilkat Online Tools

PureBasic / Salesforce Platform APIs / Themes

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/services/data/v{{version}}/theme",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "themeItems": [
    ;     {
    ;       "colors": [
    ;         {
    ;           "color": "5867E8",
    ;           "context": "primary",
    ;           "theme": "theme4"
    ;         },
    ;         {
    ;           "color": "236FBD",
    ;           "context": "primary",
    ;           "theme": "theme3"
    ;         }
    ;       ],
    ;       "icons": [
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 32,
    ;           "theme": "theme3",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/accounts32.png",
    ;           "width": 32
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 16,
    ;           "theme": "theme3",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/accounts16.png",
    ;           "width": 16
    ;         },
    ;         {
    ;           "contentType": "image/svg+xml",
    ;           "height": 0,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account.svg",
    ;           "width": 0
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 60,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_60.png",
    ;           "width": 60
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 120,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_120.png",
    ;           "width": 120
    ;         }
    ;       ],
    ;       "name": "Account"
    ;     },
    ;     {
    ;       "colors": [
    ;         {
    ;           "color": "5867E8",
    ;           "context": "primary",
    ;           "theme": "theme4"
    ;         },
    ;         {
    ;           "color": "5867E8",
    ;           "context": "primary",
    ;           "theme": "theme3"
    ;         }
    ;       ],
    ;       "icons": [
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 32,
    ;           "theme": "theme3",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/account_brand32.png",
    ;           "width": 32
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 16,
    ;           "theme": "theme3",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/account_brand16.png",
    ;           "width": 16
    ;         },
    ;         {
    ;           "contentType": "image/svg+xml",
    ;           "height": 0,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_brand.svg",
    ;           "width": 0
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 60,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_brand_60.png",
    ;           "width": 60
    ;         },
    ;         {
    ;           "contentType": "image/png",
    ;           "height": 120,
    ;           "theme": "theme4",
    ;           "url": "https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/brand_120.png",
    ;           "width": 120
    ;         }
    ;       ],
    ;       "name": "AccountBrand"
    ;     }
    ;   ]
    ; }

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

    name.s
    j.i
    count_j.i
    color.s
    context.s
    theme.s
    contentType.s
    height.i
    url.s
    width.i

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"themeItems")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        name = CkJsonObject::ckStringOf(jResp,"themeItems[i].name")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"themeItems[i].colors")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            color = CkJsonObject::ckStringOf(jResp,"themeItems[i].colors[j].color")
            context = CkJsonObject::ckStringOf(jResp,"themeItems[i].colors[j].context")
            theme = CkJsonObject::ckStringOf(jResp,"themeItems[i].colors[j].theme")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"themeItems[i].icons")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            contentType = CkJsonObject::ckStringOf(jResp,"themeItems[i].icons[j].contentType")
            height = CkJsonObject::ckIntOf(jResp,"themeItems[i].icons[j].height")
            theme = CkJsonObject::ckStringOf(jResp,"themeItems[i].icons[j].theme")
            url = CkJsonObject::ckStringOf(jResp,"themeItems[i].icons[j].url")
            width = CkJsonObject::ckIntOf(jResp,"themeItems[i].icons[j].width")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
https://domain.com/services/data/v{{version}}/theme

Postman Collection Item JSON

{
  "name": "Themes",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/theme",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "theme"
      ]
    },
    "description": "Gets the list of icons and colors used by themes in the Salesforce application. Theme information is provided for objects in your organization that use icons and colors in the Salesforce UI.\n\nThe If-Modified-Since header can be used with this resource, with a date format of EEE, dd MMM yyyy HH:mm:ss z. When this header is used, if the object metadata has not changed since the provided date, a 304 Not Modified status code is returned, with no response body.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_themes.htm"
  },
  "response": [
    {
      "name": "Themes",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": ""
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/theme",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "theme"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 27 Sep 2023 15:30:15 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=8/15000"
        },
        {
          "key": "ETag",
          "value": "\"81846348--gzip\""
        },
        {
          "key": "Last-Modified",
          "value": "Tue, 19 Sep 2023 22:01:04 GMT"
        },
        {
          "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    \"themeItems\": [\n        {\n            \"colors\": [\n                {\n                    \"color\": \"5867E8\",\n                    \"context\": \"primary\",\n                    \"theme\": \"theme4\"\n                },\n                {\n                    \"color\": \"236FBD\",\n                    \"context\": \"primary\",\n                    \"theme\": \"theme3\"\n                }\n            ],\n            \"icons\": [\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 32,\n                    \"theme\": \"theme3\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/accounts32.png\",\n                    \"width\": 32\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 16,\n                    \"theme\": \"theme3\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/accounts16.png\",\n                    \"width\": 16\n                },\n                {\n                    \"contentType\": \"image/svg+xml\",\n                    \"height\": 0,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account.svg\",\n                    \"width\": 0\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 60,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_60.png\",\n                    \"width\": 60\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 120,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_120.png\",\n                    \"width\": 120\n                }\n            ],\n            \"name\": \"Account\"\n        },\n        {\n            \"colors\": [\n                {\n                    \"color\": \"5867E8\",\n                    \"context\": \"primary\",\n                    \"theme\": \"theme4\"\n                },\n                {\n                    \"color\": \"5867E8\",\n                    \"context\": \"primary\",\n                    \"theme\": \"theme3\"\n                }\n            ],\n            \"icons\": [\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 32,\n                    \"theme\": \"theme3\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/account_brand32.png\",\n                    \"width\": 32\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 16,\n                    \"theme\": \"theme3\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/account_brand16.png\",\n                    \"width\": 16\n                },\n                {\n                    \"contentType\": \"image/svg+xml\",\n                    \"height\": 0,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_brand.svg\",\n                    \"width\": 0\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 60,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/account_brand_60.png\",\n                    \"width\": 60\n                },\n                {\n                    \"contentType\": \"image/png\",\n                    \"height\": 120,\n                    \"theme\": \"theme4\",\n                    \"url\": \"https://nto-df17-demo-dev-ed.my.salesforce.com/img/icon/t4v35/standard/brand_120.png\",\n                    \"width\": 120\n                }\n            ],\n            \"name\": \"AccountBrand\"\n        }\n    ]\n}"
    }
  ]
}