Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
// 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) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",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": [
]
}