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();
CkHttp_putBasicAuth(http,TRUE);
CkHttp_putLogin(http,"username");
CkHttp_putPassword(http,"password");
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "Carson Wentz",
// "address": "100 S. Broad Street",
// "city": "Philadelphia",
// "region": "PA",
// "country": "US",
// "postal": "19103",
// "merchid": "{{merchid}}",
// "account": "{{account}}",
// "expiry": "{{expiry}}",
// "currency": "{{currency}}"
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"name","Carson Wentz");
CkJsonObject_UpdateString(json,"address","100 S. Broad Street");
CkJsonObject_UpdateString(json,"city","Philadelphia");
CkJsonObject_UpdateString(json,"region","PA");
CkJsonObject_UpdateString(json,"country","US");
CkJsonObject_UpdateString(json,"postal","19103");
CkJsonObject_UpdateString(json,"merchid","{{merchid}}");
CkJsonObject_UpdateString(json,"account","{{account}}");
CkJsonObject_UpdateString(json,"expiry","{{expiry}}");
CkJsonObject_UpdateString(json,"currency","{{currency}}");
CkHttp_SetRequestHeader(http,"Authorization","{{Authorization}}");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://domain.com/profile",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
-u 'username:password'
-H "Authorization: {{Authorization}}"
-H "Content-Type: application/json"
-d '{
"name": "Carson Wentz",
"address": "100 S. Broad Street",
"city": "Philadelphia",
"region": "PA",
"country": "US",
"postal": "19103",
"merchid": "{{merchid}}",
"account": "{{account}}",
"expiry": "{{expiry}}",
"currency": "{{currency}}"
}'
https://domain.com/profile
Postman Collection Item JSON
{
"name": "Profile (Create/Update)",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"profileid\", jsonData.profileid);",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"acctid\", jsonData.acctid);"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "testing123",
"type": "string"
},
{
"key": "username",
"value": "testing",
"type": "string"
},
{
"key": "showPassword",
"value": false,
"type": "boolean"
}
]
},
"method": "PUT",
"header": [
{
"key": "Authorization",
"value": "{{Authorization}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Carson Wentz\",\n \"address\": \"100 S. Broad Street\",\n \"city\": \"Philadelphia\",\n \"region\": \"PA\",\n \"country\": \"US\",\n \"postal\": \"19103\",\n \"merchid\": \"{{merchid}}\",\n \"account\": \"{{account}}\",\n \"expiry\": \"{{expiry}}\",\n \"currency\": \"{{currency}}\"\n}"
},
"url": {
"raw": "{{url}}/profile",
"host": [
"{{url}}"
],
"path": [
"profile"
]
},
"description": "[Profile Documentation](https://developer.cardconnect.com/cardconnect-api#profile)"
},
"response": [
]
}