Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sHeaderName
String sHeaderValue
Integer iSequenceNumber
String sPrincipalName
String sPrincipalType
Integer j
Integer iCount_j
String sAuthenticationProtocol
String sAuthenticationStatus
String sDeveloperName
String sId
String sMasterLabel
String sUrl
Integer i
Integer iCount_i
String sTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "developerName": "SampleExternalCredential",
// "masterLabel": "Sample External Credential",
// "authenticationProtocol": "Custom",
// "principals": [
// {
// "principalName": "SamplePrincipal",
// "principalType": "NamedPrincipal",
// "sequenceNumber": 1
// }
// ],
// "customHeaders": [
// {
// "headerName": "SampleHeader",
// "headerValue": "SampleHeaderValue",
// "sequenceNumber": 1
// }
// ]
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "developerName" "SampleExternalCredential" To iSuccess
Get ComUpdateString Of hoJson "masterLabel" "Sample External Credential" To iSuccess
Get ComUpdateString Of hoJson "authenticationProtocol" "Custom" To iSuccess
Get ComUpdateString Of hoJson "principals[0].principalName" "SamplePrincipal" To iSuccess
Get ComUpdateString Of hoJson "principals[0].principalType" "NamedPrincipal" To iSuccess
Get ComUpdateInt Of hoJson "principals[0].sequenceNumber" 1 To iSuccess
Get ComUpdateString Of hoJson "customHeaders[0].headerName" "SampleHeader" To iSuccess
Get ComUpdateString Of hoJson "customHeaders[0].headerValue" "SampleHeaderValue" To iSuccess
Get ComUpdateInt Of hoJson "customHeaders[0].sequenceNumber" 1 To iSuccess
// Adds the "Authorization: Bearer <access_token>" header.
Set ComAuthToken Of hoHttp To "<access_token>"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" "https://domain.com/services/data/v{{version}}/named-credentials/external-credentials" vJson "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "authenticationProtocol": "Custom",
// "authenticationStatus": "Unknown",
// "customHeaders": [
// {
// "headerName": "SampleHeader",
// "headerValue": "SampleHeaderValue",
// "id": "0pu2o000000KymkAAC",
// "sequenceNumber": 1
// }
// ],
// "developerName": "SampleExternalCredential",
// "id": "0pt2o000000CaU0AAK",
// "masterLabel": "Sample External Credential",
// "parameters": [
// ],
// "principals": [
// {
// "authenticationStatus": "Unknown",
// "id": "0pu2o000000KymjAAC",
// "parameters": [
// ],
// "principalAccess": [
// ],
// "principalName": "SamplePrincipal",
// "principalType": "NamedPrincipal",
// "sequenceNumber": 1
// }
// ],
// "relatedNamedCredentials": [
// ],
// "url": "/services/data/v58.0/named-credentials/external-credentials/SampleExternalCredential"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Get ComStringOf Of hoJResp "authenticationProtocol" To sAuthenticationProtocol
Get ComStringOf Of hoJResp "authenticationStatus" To sAuthenticationStatus
Get ComStringOf Of hoJResp "developerName" To sDeveloperName
Get ComStringOf Of hoJResp "id" To sId
Get ComStringOf Of hoJResp "masterLabel" To sMasterLabel
Get ComStringOf Of hoJResp "url" To sUrl
Move 0 To i
Get ComSizeOfArray Of hoJResp "customHeaders" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "customHeaders[i].headerName" To sHeaderName
Get ComStringOf Of hoJResp "customHeaders[i].headerValue" To sHeaderValue
Get ComStringOf Of hoJResp "customHeaders[i].id" To sId
Get ComIntOf Of hoJResp "customHeaders[i].sequenceNumber" To iSequenceNumber
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "parameters" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "principals" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "principals[i].authenticationStatus" To sAuthenticationStatus
Get ComStringOf Of hoJResp "principals[i].id" To sId
Get ComStringOf Of hoJResp "principals[i].principalName" To sPrincipalName
Get ComStringOf Of hoJResp "principals[i].principalType" To sPrincipalType
Get ComIntOf Of hoJResp "principals[i].sequenceNumber" To iSequenceNumber
Move 0 To j
Get ComSizeOfArray Of hoJResp "principals[i].parameters" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "principals[i].principalAccess" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "relatedNamedCredentials" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"developerName": "SampleExternalCredential",
"masterLabel": "Sample External Credential",
"authenticationProtocol": "Custom",
"principals": [
{
"principalName": "SamplePrincipal",
"principalType": "NamedPrincipal",
"sequenceNumber": 1
}
],
"customHeaders": [
{
"headerName": "SampleHeader",
"headerValue": "SampleHeaderValue",
"sequenceNumber": 1
}
]
}'
https://domain.com/services/data/v{{version}}/named-credentials/external-credentials
Postman Collection Item JSON
{
"name": "Create External Credential",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"developerName\": \"SampleExternalCredential\",\n \"masterLabel\": \"Sample External Credential\",\n \"authenticationProtocol\": \"Custom\",\n \"principals\": [\n {\n \"principalName\": \"SamplePrincipal\",\n \"principalType\": \"NamedPrincipal\",\n \"sequenceNumber\": 1\n }\n ],\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleHeaderValue\",\n \"sequenceNumber\": 1\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/named-credentials/external-credentials",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"named-credentials",
"external-credentials"
]
},
"description": "Create an external credential."
},
"response": [
{
"name": "Successful Create External Credential",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"developerName\": \"SampleExternalCredential\",\n \"masterLabel\": \"Sample External Credential\",\n \"authenticationProtocol\": \"Custom\",\n \"principals\": [\n {\n \"principalName\": \"SamplePrincipal\",\n \"principalType\": \"NamedPrincipal\",\n \"sequenceNumber\": 1\n }\n ],\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleHeaderValue\",\n \"sequenceNumber\": 1\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/named-credentials/external-credentials",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"named-credentials",
"external-credentials"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Mon, 20 Nov 2023 16:53:51 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": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"authenticationProtocol\": \"Custom\",\n \"authenticationStatus\": \"Unknown\",\n \"customHeaders\": [\n {\n \"headerName\": \"SampleHeader\",\n \"headerValue\": \"SampleHeaderValue\",\n \"id\": \"0pu2o000000KymkAAC\",\n \"sequenceNumber\": 1\n }\n ],\n \"developerName\": \"SampleExternalCredential\",\n \"id\": \"0pt2o000000CaU0AAK\",\n \"masterLabel\": \"Sample External Credential\",\n \"parameters\": [],\n \"principals\": [\n {\n \"authenticationStatus\": \"Unknown\",\n \"id\": \"0pu2o000000KymjAAC\",\n \"parameters\": [],\n \"principalAccess\": [],\n \"principalName\": \"SamplePrincipal\",\n \"principalType\": \"NamedPrincipal\",\n \"sequenceNumber\": 1\n }\n ],\n \"relatedNamedCredentials\": [],\n \"url\": \"/services/data/v58.0/named-credentials/external-credentials/SampleExternalCredential\"\n}"
}
]
}