Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_HeaderName
string ls_HeaderValue
integer li_SequenceNumber
integer li_AllowMergeFieldsInBody
integer li_AllowMergeFieldsInHeader
integer li_GenerateAuthorizationHeader
string ls_CalloutUrl
string ls_DeveloperName
string ls_Id
string ls_MasterLabel
string ls_V_type
string ls_Url
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
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "masterLabel": "SamplePrivateLabel",
// "type": "SecuredEndpoint",
// "calloutUrl": "https://api.example.com",
// "externalCredentials": [
// {
// "developerName": "SampleExternalCredential"
// }
// ],
// "customHeaders": [
// {
// "headerName": "SampleHeader",
// "headerValue": "SampleValue",
// "sequenceNumber": 1
// }
// ],
// "calloutOptions": {
// "allowMergeFieldsInBody": false,
// "allowMergeFieldsInHeader": true,
// "generateAuthorizationHeader": true
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("masterLabel","SamplePrivateLabel")
loo_Json.UpdateString("type","SecuredEndpoint")
loo_Json.UpdateString("calloutUrl","https://api.example.com")
loo_Json.UpdateString("externalCredentials[0].developerName","SampleExternalCredential")
loo_Json.UpdateString("customHeaders[0].headerName","SampleHeader")
loo_Json.UpdateString("customHeaders[0].headerValue","SampleValue")
loo_Json.UpdateInt("customHeaders[0].sequenceNumber",1)
loo_Json.UpdateBool("calloutOptions.allowMergeFieldsInBody",0)
loo_Json.UpdateBool("calloutOptions.allowMergeFieldsInHeader",1)
loo_Json.UpdateBool("calloutOptions.generateAuthorizationHeader",1)
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://domain.com/services/data/v{{version}}/named-credentials/named-credential-setup/:DEVELOPER_NAME",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
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_Json
destroy loo_SbRequestBody
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)
// {
// "calloutOptions": {
// "allowMergeFieldsInBody": false,
// "allowMergeFieldsInHeader": true,
// "generateAuthorizationHeader": true
// },
// "calloutUrl": "https://api.example.com",
// "customHeaders": [
// {
// "headerName": "SampleHeader",
// "headerValue": "SampleValue",
// "id": "0pv2o000000PAv6AAG",
// "sequenceNumber": 1
// }
// ],
// "developerName": "SamplePrivate",
// "externalCredentials": [
// {
// "developerName": "SampleExternalCredential",
// "id": "0pt2o000000CaU0AAK",
// "masterLabel": "Sample External Credential",
// "url": "/services/data/v58.0/named-credentials/external-credentials/SampleExternalCredential"
// }
// ],
// "id": "0XA2o000000XaAQGA0",
// "masterLabel": "SamplePrivateLabel",
// "parameters": [
// ],
// "type": "SecuredEndpoint",
// "url": "/services/data/v58.0/named-credentials/named-credential-setup/SamplePrivate"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
li_AllowMergeFieldsInBody = loo_JResp.BoolOf("calloutOptions.allowMergeFieldsInBody")
li_AllowMergeFieldsInHeader = loo_JResp.BoolOf("calloutOptions.allowMergeFieldsInHeader")
li_GenerateAuthorizationHeader = loo_JResp.BoolOf("calloutOptions.generateAuthorizationHeader")
ls_CalloutUrl = loo_JResp.StringOf("calloutUrl")
ls_DeveloperName = loo_JResp.StringOf("developerName")
ls_Id = loo_JResp.StringOf("id")
ls_MasterLabel = loo_JResp.StringOf("masterLabel")
ls_V_type = loo_JResp.StringOf("type")
ls_Url = loo_JResp.StringOf("url")
i = 0
li_Count_i = loo_JResp.SizeOfArray("customHeaders")
do while i < li_Count_i
loo_JResp.I = i
ls_HeaderName = loo_JResp.StringOf("customHeaders[i].headerName")
ls_HeaderValue = loo_JResp.StringOf("customHeaders[i].headerValue")
ls_Id = loo_JResp.StringOf("customHeaders[i].id")
li_SequenceNumber = loo_JResp.IntOf("customHeaders[i].sequenceNumber")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("externalCredentials")
do while i < li_Count_i
loo_JResp.I = i
ls_DeveloperName = loo_JResp.StringOf("externalCredentials[i].developerName")
ls_Id = loo_JResp.StringOf("externalCredentials[i].id")
ls_MasterLabel = loo_JResp.StringOf("externalCredentials[i].masterLabel")
ls_Url = loo_JResp.StringOf("externalCredentials[i].url")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("parameters")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"masterLabel": "SamplePrivateLabel",
"type": "SecuredEndpoint",
"calloutUrl": "https://api.example.com",
"externalCredentials": [
{
"developerName": "SampleExternalCredential"
}
],
"customHeaders": [
{
"headerName": "SampleHeader",
"headerValue": "SampleValue",
"sequenceNumber": 1
}
],
"calloutOptions": {
"allowMergeFieldsInBody": false,
"allowMergeFieldsInHeader": true,
"generateAuthorizationHeader": true
}
}'
https://domain.com/services/data/v{{version}}/named-credentials/named-credential-setup/:DEVELOPER_NAME
Postman Collection Item JSON
{
"name": "Update Named Credential",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"masterLabel\": \"SamplePrivateLabel\",\n \"type\": \"SecuredEndpoint\",\n \"calloutUrl\": \"https://api.example.com\",\n \"externalCredentials\": [\n {\n \"developerName\": \"SampleExternalCredential\"\n }\n ],\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleValue\",\n \"sequenceNumber\": 1\n }\n ],\n \"calloutOptions\": {\n \"allowMergeFieldsInBody\": false,\n \"allowMergeFieldsInHeader\": true,\n \"generateAuthorizationHeader\": true\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/named-credentials/named-credential-setup/:DEVELOPER_NAME",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"named-credentials",
"named-credential-setup",
":DEVELOPER_NAME"
],
"variable": [
{
"key": "DEVELOPER_NAME",
"value": ""
}
]
},
"description": "Update a named credential."
},
"response": [
{
"name": "Successful Update Named Credential",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"masterLabel\": \"SamplePrivateLabel\",\n \"type\": \"SecuredEndpoint\",\n \"calloutUrl\": \"https://api.example.com\",\n \"externalCredentials\": [\n {\n \"developerName\": \"SampleExternalCredential\"\n }\n ],\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleValue\",\n \"sequenceNumber\": 1\n }\n ],\n \"calloutOptions\": {\n \"allowMergeFieldsInBody\": false,\n \"allowMergeFieldsInHeader\": true,\n \"generateAuthorizationHeader\": true\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/named-credentials/named-credential-setup/:DEVELOPER_NAME",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"named-credentials",
"named-credential-setup",
":DEVELOPER_NAME"
],
"variable": [
{
"key": "DEVELOPER_NAME",
"value": "SamplePrivate"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Mon, 20 Nov 2023 16:54:57 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": "Content-Type",
"value": "application/json;charset=UTF-8"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"calloutOptions\": {\n \"allowMergeFieldsInBody\": false,\n \"allowMergeFieldsInHeader\": true,\n \"generateAuthorizationHeader\": true\n },\n \"calloutUrl\": \"https://api.example.com\",\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleValue\",\n \"id\": \"0pv2o000000PAv6AAG\",\n \"sequenceNumber\": 1\n }\n ],\n \"developerName\": \"SamplePrivate\",\n \"externalCredentials\": [\n {\n \"developerName\": \"SampleExternalCredential\",\n \"id\": \"0pt2o000000CaU0AAK\",\n \"masterLabel\": \"Sample External Credential\",\n \"url\": \"/services/data/v58.0/named-credentials/external-credentials/SampleExternalCredential\"\n }\n ],\n \"id\": \"0XA2o000000XaAQGA0\",\n \"masterLabel\": \"SamplePrivateLabel\",\n \"parameters\": [],\n \"type\": \"SecuredEndpoint\",\n \"url\": \"/services/data/v58.0/named-credentials/named-credential-setup/SamplePrivate\"\n}"
}
]
}