Back to Collection Items
var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "externalCredential": "test",
// "authenticationProtocol": "Custom",
// "principalName": "test",
// "principalType": "NamedPrincipal",
// "credentials": {
// "testCredential": {
// "value": "000000",
// "encrypted": true
// }
// }
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'externalCredential','test');
CkJsonObject_UpdateString(json,'authenticationProtocol','Custom');
CkJsonObject_UpdateString(json,'principalName','test');
CkJsonObject_UpdateString(json,'principalType','NamedPrincipal');
CkJsonObject_UpdateString(json,'credentials.testCredential.value','000000');
CkJsonObject_UpdateBool(json,'credentials.testCredential.encrypted',True);
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');
sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp := CkHttp_PTextSb(http,'PUT','https://domain.com/services/data/v{{version}}/named-credentials/credential',sbRequestBody,'utf-8','application/json',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"externalCredential": "test",
"authenticationProtocol": "Custom",
"principalName": "test",
"principalType": "NamedPrincipal",
"credentials": {
"testCredential": {
"value": "000000",
"encrypted": true
}
}
}'
https://domain.com/services/data/v{{version}}/named-credentials/credential
Postman Collection Item JSON
{
"name": "Update Credential",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"externalCredential\": \"test\",\n \"authenticationProtocol\": \"Custom\",\n \"principalName\": \"test\",\n \"principalType\": \"NamedPrincipal\",\n \"credentials\": {\n \"testCredential\": {\n \"value\": \"000000\",\n \"encrypted\": true\n }\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/named-credentials/credential",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"named-credentials",
"credential"
]
},
"description": "Update a credential."
},
"response": [
]
}