Swift3 / CleverTap API / Upload Events API
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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"
// }
// }
// ]
// }
let json = CkoJsonObject()!
json.update("d[0].identity", value: "34322423")
json.update("d[0].type", value: "event")
json.update("d[0].evtName", value: "Product viewed")
json.update("d[0].evtData.\"Product name\"", value: "Casio Chronograph Watch")
json.update("d[0].evtData.Category", value: "Mens Watch")
json.updateNumber("d[0].evtData.Price", numericStr: "59.99")
json.update("d[0].evtData.Currency", value: "USD")
http.setRequestHeader("X-CleverTap-Passcode", value: "{{passcode}}")
http.setRequestHeader("X-CleverTap-Account-Id", value: "{{id}}")
http.setRequestHeader("Content-Type", value: "application/json")
var resp: CkoHttpResponse? = http.postJson3("https://api.clevertap.com/1/upload", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
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": [
]
}