Chilkat Online Tools

DataFlex / CleverTap API / Upload Events API

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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"
    //       }
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "d[0].identity" "34322423" To iSuccess
    Get ComUpdateString Of hoJson "d[0].type" "event" To iSuccess
    Get ComUpdateString Of hoJson "d[0].evtName" "Product viewed" To iSuccess
    Get ComUpdateString Of hoJson 'd[0].evtData."Product name"' "Casio Chronograph Watch" To iSuccess
    Get ComUpdateString Of hoJson "d[0].evtData.Category" "Mens Watch" To iSuccess
    Get ComUpdateNumber Of hoJson "d[0].evtData.Price" "59.99" To iSuccess
    Get ComUpdateString Of hoJson "d[0].evtData.Currency" "USD" To iSuccess

    Send ComSetRequestHeader To hoHttp "X-CleverTap-Passcode" "{{passcode}}"
    Send ComSetRequestHeader To hoHttp "X-CleverTap-Account-Id" "{{id}}"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.clevertap.com/1/upload" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}