Chilkat Online Tools

C / CleverTap API / Test Webhook Payload

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    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.

    // {
    //   "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) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",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": [
  ]
}