Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / List named credentials

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_V_Type
string ls_V_Url
string ls_Id
integer li_IsDeleted
string ls_DeveloperName
string ls_Language
string ls_MasterLabel
string ls_NamespacePrefix
string ls_CreatedDate
string ls_CreatedById
string ls_LastModifiedDate
string ls_LastModifiedById
string ls_SystemModstamp
string ls_Endpoint
string ls_PrincipalType
string ls_JwtIssuer
string ls_JwtFormulaSubject
string ls_JwtTextSubject
string ls_JwtValidityPeriodSeconds
string ls_JwtAudience
string ls_AuthTokenEndpointUrl
integer li_Size
integer li_TotalSize
integer li_Done
string ls_QueryLocator
string ls_EntityTypeName
integer i
integer li_Count_i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_QueryParams = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject")

loo_QueryParams.UpdateString("q","SELECT FIELDS(ALL) FROM NamedCredential LIMIT 200")

// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"

loo_Resp = loo_Http.QuickRequestParams("GET","https://domain.com/services/data/v{{version}}/tooling/query/",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

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

// {
//   "size": 1,
//   "totalSize": 1,
//   "done": true,
//   "queryLocator": null,
//   "entityTypeName": "NamedCredential",
//   "records": [
//     {
//       "attributes": {
//         "type": "NamedCredential",
//         "url": "/services/data/v58.0/tooling/sobjects/NamedCredential/0XA4H000000TNRhWAO"
//       },
//       "Id": "0XA4H000000TNRhWAO",
//       "IsDeleted": false,
//       "DeveloperName": "Slack_Webhook_for_integration_Channel",
//       "Language": "en_US",
//       "MasterLabel": "Slack Webhook for #integration Channel",
//       "NamespacePrefix": null,
//       "CreatedDate": "2020-11-06T14:04:44.000+0000",
//       "CreatedById": "00558000000yFyDAAU",
//       "LastModifiedDate": "2020-11-06T14:04:44.000+0000",
//       "LastModifiedById": "00558000000yFyDAAU",
//       "SystemModstamp": "2020-11-06T14:04:44.000+0000",
//       "Endpoint": "https://hooks.slack.com/services/SECRET",
//       "PrincipalType": "Anonymous",
//       "JwtIssuer": null,
//       "JwtFormulaSubject": null,
//       "JwtTextSubject": null,
//       "JwtValidityPeriodSeconds": null,
//       "JwtAudience": null,
//       "AuthTokenEndpointUrl": null
//     }
//   ]
// }

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

li_Size = loo_JResp.IntOf("size")
li_TotalSize = loo_JResp.IntOf("totalSize")
li_Done = loo_JResp.BoolOf("done")
ls_QueryLocator = loo_JResp.StringOf("queryLocator")
ls_EntityTypeName = loo_JResp.StringOf("entityTypeName")
i = 0
li_Count_i = loo_JResp.SizeOfArray("records")
do while i < li_Count_i
    loo_JResp.I = i
    ls_V_Type = loo_JResp.StringOf("records[i].attributes.type")
    ls_V_Url = loo_JResp.StringOf("records[i].attributes.url")
    ls_Id = loo_JResp.StringOf("records[i].Id")
    li_IsDeleted = loo_JResp.BoolOf("records[i].IsDeleted")
    ls_DeveloperName = loo_JResp.StringOf("records[i].DeveloperName")
    ls_Language = loo_JResp.StringOf("records[i].Language")
    ls_MasterLabel = loo_JResp.StringOf("records[i].MasterLabel")
    ls_NamespacePrefix = loo_JResp.StringOf("records[i].NamespacePrefix")
    ls_CreatedDate = loo_JResp.StringOf("records[i].CreatedDate")
    ls_CreatedById = loo_JResp.StringOf("records[i].CreatedById")
    ls_LastModifiedDate = loo_JResp.StringOf("records[i].LastModifiedDate")
    ls_LastModifiedById = loo_JResp.StringOf("records[i].LastModifiedById")
    ls_SystemModstamp = loo_JResp.StringOf("records[i].SystemModstamp")
    ls_Endpoint = loo_JResp.StringOf("records[i].Endpoint")
    ls_PrincipalType = loo_JResp.StringOf("records[i].PrincipalType")
    ls_JwtIssuer = loo_JResp.StringOf("records[i].JwtIssuer")
    ls_JwtFormulaSubject = loo_JResp.StringOf("records[i].JwtFormulaSubject")
    ls_JwtTextSubject = loo_JResp.StringOf("records[i].JwtTextSubject")
    ls_JwtValidityPeriodSeconds = loo_JResp.StringOf("records[i].JwtValidityPeriodSeconds")
    ls_JwtAudience = loo_JResp.StringOf("records[i].JwtAudience")
    ls_AuthTokenEndpointUrl = loo_JResp.StringOf("records[i].AuthTokenEndpointUrl")
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -G -d "q=SELECT%20FIELDS%28ALL%29%20FROM%20NamedCredential%20LIMIT%20200"
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/tooling/query/

Postman Collection Item JSON

{
  "name": "List named credentials",
  "protocolProfileBehavior": {
    "strictSSL": false,
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=SELECT FIELDS(ALL) FROM NamedCredential LIMIT 200",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "tooling",
        "query",
        ""
      ],
      "query": [
        {
          "key": "q",
          "value": "SELECT FIELDS(ALL) FROM NamedCredential LIMIT 200"
        }
      ]
    }
  },
  "response": [
    {
      "name": "List named credentials",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=SELECT FIELDS(ALL) FROM NamedCredential LIMIT 200",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "tooling",
            "query",
            ""
          ],
          "query": [
            {
              "key": "q",
              "value": "SELECT FIELDS(ALL) FROM NamedCredential LIMIT 200"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Mon, 03 Jul 2023 13:09:27 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": "Sforce-Limit-Info",
          "value": "api-usage=5/15000"
        },
        {
          "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    \"size\": 1,\n    \"totalSize\": 1,\n    \"done\": true,\n    \"queryLocator\": null,\n    \"entityTypeName\": \"NamedCredential\",\n    \"records\": [\n        {\n            \"attributes\": {\n                \"type\": \"NamedCredential\",\n                \"url\": \"/services/data/v58.0/tooling/sobjects/NamedCredential/0XA4H000000TNRhWAO\"\n            },\n            \"Id\": \"0XA4H000000TNRhWAO\",\n            \"IsDeleted\": false,\n            \"DeveloperName\": \"Slack_Webhook_for_integration_Channel\",\n            \"Language\": \"en_US\",\n            \"MasterLabel\": \"Slack Webhook for #integration Channel\",\n            \"NamespacePrefix\": null,\n            \"CreatedDate\": \"2020-11-06T14:04:44.000+0000\",\n            \"CreatedById\": \"00558000000yFyDAAU\",\n            \"LastModifiedDate\": \"2020-11-06T14:04:44.000+0000\",\n            \"LastModifiedById\": \"00558000000yFyDAAU\",\n            \"SystemModstamp\": \"2020-11-06T14:04:44.000+0000\",\n            \"Endpoint\": \"https://hooks.slack.com/services/SECRET\",\n            \"PrincipalType\": \"Anonymous\",\n            \"JwtIssuer\": null,\n            \"JwtFormulaSubject\": null,\n            \"JwtTextSubject\": null,\n            \"JwtValidityPeriodSeconds\": null,\n            \"JwtAudience\": null,\n            \"AuthTokenEndpointUrl\": null\n        }\n    ]\n}"
    }
  ]
}