Chilkat Online Tools

delphiDll / CleverTap API / Test Webhook Payload

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
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.

// {
//   "is_test": true,
//   "targetId": 1234,
//   "key_values": {
//     "key": "value"
//   },
//   "profiles": [
//     {
//       "Identity": "UserId",
//       "Email": "User@user.com",
//       "push_token": "Token"
//     },
//     {
//       "Identity": "UserId",
//       "Email": "User@user.com",
//       "push_token": "Token"
//     },
//     {
//       "Identity": "UserId",
//       "Email": "User@user.com",
//       "push_token": "Token"
//     },
//     {
//       "Identity": "UserId",
//       "Email": "User@user.com",
//       "push_token": "Token"
//     },
//     {
//       "Identity": "UserId",
//       "Email": "User@user.com",
//       "push_token": "Token"
//     }
//   ]
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateBool(json,'is_test',True);
CkJsonObject_UpdateInt(json,'targetId',1234);
CkJsonObject_UpdateString(json,'key_values.key','value');
CkJsonObject_UpdateString(json,'profiles[0].Identity','UserId');
CkJsonObject_UpdateString(json,'profiles[0].Email','User@user.com');
CkJsonObject_UpdateString(json,'profiles[0].push_token','Token');
CkJsonObject_UpdateString(json,'profiles[1].Identity','UserId');
CkJsonObject_UpdateString(json,'profiles[1].Email','User@user.com');
CkJsonObject_UpdateString(json,'profiles[1].push_token','Token');
CkJsonObject_UpdateString(json,'profiles[2].Identity','UserId');
CkJsonObject_UpdateString(json,'profiles[2].Email','User@user.com');
CkJsonObject_UpdateString(json,'profiles[2].push_token','Token');
CkJsonObject_UpdateString(json,'profiles[3].Identity','UserId');
CkJsonObject_UpdateString(json,'profiles[3].Email','User@user.com');
CkJsonObject_UpdateString(json,'profiles[3].push_token','Token');
CkJsonObject_UpdateString(json,'profiles[4].Identity','UserId');
CkJsonObject_UpdateString(json,'profiles[4].Email','User@user.com');
CkJsonObject_UpdateString(json,'profiles[4].push_token','Token');

CkHttp_SetRequestHeader(http,'Content-Type','{{type}}');
CkHttp_SetRequestHeader(http,'User-Agent','{{user-agent}}');
CkHttp_SetRequestHeader(http,'Content-Length','{{content-length}}');

resp := CkHttp_PostJson3(http,'https://domain.com/','{{type}}',json);
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);

Curl Command

curl -X POST
	-H "Content-Type: {{type}}"
	-H "Content-Length: {{content-length}}"
	-H "User-Agent: {{user-agent}}"
	-d '{ "is_test" : true , "targetId" : 1234 , "key_values" : { "key" : "value"} , "profiles" : [ { "Identity" : "UserId" , "Email" : "User@user.com" , "push_token" : "Token"} , { "Identity" : "UserId" , "Email" : "User@user.com" , "push_token" : "Token"} , { "Identity" : "UserId" , "Email" : "User@user.com" , "push_token" : "Token"} , { "Identity" : "UserId" , "Email" : "User@user.com" , "push_token" : "Token"} , { "Identity" : "UserId" , "Email" : "User@user.com" , "push_token" : "Token"}]}'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Test Webhook Payload",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "{{type}}"
      },
      {
        "key": "Content-Length",
        "value": "{{content-length}}"
      },
      {
        "key": "User-Agent",
        "value": "{{user-agent}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{ \"is_test\" : true , \"targetId\" : 1234 , \"key_values\" : { \"key\" : \"value\"} , \"profiles\" : [ { \"Identity\" : \"UserId\" , \"Email\" : \"User@user.com\" , \"push_token\" : \"Token\"} , { \"Identity\" : \"UserId\" , \"Email\" : \"User@user.com\" , \"push_token\" : \"Token\"} , { \"Identity\" : \"UserId\" , \"Email\" : \"User@user.com\" , \"push_token\" : \"Token\"} , { \"Identity\" : \"UserId\" , \"Email\" : \"User@user.com\" , \"push_token\" : \"Token\"} , { \"Identity\" : \"UserId\" , \"Email\" : \"User@user.com\" , \"push_token\" : \"Token\"}]}"
    },
    "url": {
      "raw": ""
    }
  },
  "response": [
  ]
}