Chilkat Online Tools

unicodeCpp / CleverTap API / Upload Events API

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "d": [
    //     {
    //       "identity": "34322423",
    //       "type": "event",
    //       "evtName": "Product viewed",
    //       "evtData": {
    //         "Product name": "Casio Chronograph Watch",
    //         "Category": "Mens Watch",
    //         "Price": 59.99,
    //         "Currency": "USD"
    //       }
    //     }
    //   ]
    // }

    CkJsonObjectW json;
    json.UpdateString(L"d[0].identity",L"34322423");
    json.UpdateString(L"d[0].type",L"event");
    json.UpdateString(L"d[0].evtName",L"Product viewed");
    json.UpdateString(L"d[0].evtData.\"Product name\"",L"Casio Chronograph Watch");
    json.UpdateString(L"d[0].evtData.Category",L"Mens Watch");
    json.UpdateNumber(L"d[0].evtData.Price",L"59.99");
    json.UpdateString(L"d[0].evtData.Currency",L"USD");

    http.SetRequestHeader(L"X-CleverTap-Passcode",L"{{passcode}}");
    http.SetRequestHeader(L"X-CleverTap-Account-Id",L"{{id}}");
    http.SetRequestHeader(L"Content-Type",L"application/json");

    CkHttpResponseW *resp = http.PostJson3(L"https://api.clevertap.com/1/upload",L"application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

Curl Command

curl -X POST
	-H "X-CleverTap-Account-Id: {{id}}"
	-H "X-CleverTap-Passcode: {{passcode}}"
	-H "Content-Type: application/json"
	-d '{ "d": [ { "identity": "34322423", "type": "event", "evtName": "Product viewed", "evtData": { "Product name": "Casio Chronograph Watch", "Category": "Mens Watch", "Price": 59.99, "Currency": "USD" } } ] }'
https://api.clevertap.com/1/upload

Postman Collection Item JSON

{
  "name": "Upload Events API",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "X-CleverTap-Account-Id",
        "value": "{{id}}"
      },
      {
        "key": "X-CleverTap-Passcode",
        "value": "{{passcode}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{ \"d\": [ { \"identity\": \"34322423\", \"type\": \"event\", \"evtName\": \"Product viewed\", \"evtData\": { \"Product name\": \"Casio Chronograph Watch\", \"Category\": \"Mens Watch\", \"Price\": 59.99, \"Currency\": \"USD\" } } ] }"
    },
    "url": {
      "raw": "https://api.clevertap.com/1/upload",
      "protocol": "https",
      "host": [
        "api",
        "clevertap",
        "com"
      ],
      "path": [
        "1",
        "upload"
      ]
    }
  },
  "response": [
  ]
}