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;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *id;
const char *institution;
const char *access_mode;
const char *last_accessed_at;
const char *status;
const char *created_by;
const char *refresh_rate;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
CkHttp_putBasicAuth(http,TRUE);
CkHttp_putLogin(http,"{{secretId}}");
CkHttp_putPassword(http,"{{secretPassword}}");
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "password": "password",
// "password2": "pin",
// "token": "1234ab",
// "encryption_key": "customencryptionkey",
// "username_type": "001",
// "certificate": "1234567890abcd=",
// "private_key": "1234567890abcd="
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"password","password");
CkJsonObject_UpdateString(json,"password2","pin");
CkJsonObject_UpdateString(json,"token","1234ab");
CkJsonObject_UpdateString(json,"encryption_key","customencryptionkey");
CkJsonObject_UpdateString(json,"username_type","001");
CkJsonObject_UpdateString(json,"certificate","1234567890abcd=");
CkJsonObject_UpdateString(json,"private_key","1234567890abcd=");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://domain.com/api/links/:id/",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;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "<uuid>",
// "institution": "<string>",
// "access_mode": "<string>",
// "last_accessed_at": "<dateTime>",
// "status": "<string>",
// "created_by": "<uuid>",
// "refresh_rate": "<string>"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
id = CkJsonObject_stringOf(jResp,"id");
institution = CkJsonObject_stringOf(jResp,"institution");
access_mode = CkJsonObject_stringOf(jResp,"access_mode");
last_accessed_at = CkJsonObject_stringOf(jResp,"last_accessed_at");
status = CkJsonObject_stringOf(jResp,"status");
created_by = CkJsonObject_stringOf(jResp,"created_by");
refresh_rate = CkJsonObject_stringOf(jResp,"refresh_rate");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X PUT
-u '{{secretId}}:{{secretPassword}}'
-H "Content-Type: application/json"
-d '{
"password": "password",
"password2": "pin",
"token": "1234ab",
"encryption_key": "customencryptionkey",
"username_type": "001",
"certificate": "1234567890abcd=",
"private_key": "1234567890abcd="
}'
https://domain.com/api/links/:id/
Postman Collection Item JSON
{
"name": "Update",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"password\",\n \"password2\": \"pin\",\n \"token\": \"1234ab\",\n \"encryption_key\": \"customencryptionkey\",\n \"username_type\": \"001\",\n \"certificate\": \"1234567890abcd=\",\n \"private_key\": \"1234567890abcd=\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id/",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id",
""
],
"variable": [
{
"key": "id",
"value": "consequa",
"description": "(Required) The `link.id` you want to update."
}
]
},
"description": "Update the credentials of a specific link.\n\n✅ We recommend using our [Connect Widget in Update Mode](https://developers.belvo.com/docs/connect-widget-update-mode) to handle updating `invalid` or `token_required` links.\n"
},
"response": [
{
"name": "Ok",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"id\": \"<uuid>\",\n\t\"institution\": \"<string>\",\n\t\"access_mode\": \"<string>\",\n\t\"last_accessed_at\": \"<dateTime>\",\n\t\"status\": \"<string>\",\n\t\"created_by\": \"<uuid>\",\n\t\"refresh_rate\": \"<string>\"\n}"
},
{
"name": "Bad request error",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "Unauthorized",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "Too Many Sessions",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "MFA Token Required",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Precondition Required",
"code": 428,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"code\": \"<string>\",\n\t\"message\": \"<string>\",\n\t\"request_id\": \"<uuid>\",\n\t\"session\": \"<uuid>\",\n\t\"expiry\": \"<integer>\",\n\t\"link\": \"<uuid>\",\n\t\"token_generation_data\": {\n\t\t\"instructions\": \"<string>\",\n\t\t\"type\": \"<string>\",\n\t\t\"value\": \"<string>\"\n\t}\n}"
},
{
"name": "Unexpected Error",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"password\": \"<string>\",\n \"password2\": \"<string>\",\n \"token\": \"<string>\",\n \"encryption_key\": \"<string>\",\n \"username_type\": \"<string>\",\n \"certificate\": \"<string>\",\n \"private_key\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/api/links/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"links",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
}
]
}