PureBasic / CleverTap API / Test Webhook Payload
Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
; 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.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateBool(json,"is_test",1)
CkJsonObject::ckUpdateInt(json,"targetId",1234)
CkJsonObject::ckUpdateString(json,"key_values.key","value")
CkJsonObject::ckUpdateString(json,"profiles[0].Identity","UserId")
CkJsonObject::ckUpdateString(json,"profiles[0].Email","User@user.com")
CkJsonObject::ckUpdateString(json,"profiles[0].push_token","Token")
CkJsonObject::ckUpdateString(json,"profiles[1].Identity","UserId")
CkJsonObject::ckUpdateString(json,"profiles[1].Email","User@user.com")
CkJsonObject::ckUpdateString(json,"profiles[1].push_token","Token")
CkJsonObject::ckUpdateString(json,"profiles[2].Identity","UserId")
CkJsonObject::ckUpdateString(json,"profiles[2].Email","User@user.com")
CkJsonObject::ckUpdateString(json,"profiles[2].push_token","Token")
CkJsonObject::ckUpdateString(json,"profiles[3].Identity","UserId")
CkJsonObject::ckUpdateString(json,"profiles[3].Email","User@user.com")
CkJsonObject::ckUpdateString(json,"profiles[3].push_token","Token")
CkJsonObject::ckUpdateString(json,"profiles[4].Identity","UserId")
CkJsonObject::ckUpdateString(json,"profiles[4].Email","User@user.com")
CkJsonObject::ckUpdateString(json,"profiles[4].push_token","Token")
CkHttp::ckSetRequestHeader(http,"Content-Type","{{type}}")
CkHttp::ckSetRequestHeader(http,"User-Agent","{{user-agent}}")
CkHttp::ckSetRequestHeader(http,"Content-Length","{{content-length}}")
resp.i = CkHttp::ckPostJson3(http,"https://domain.com/","{{type}}",json)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
Debug Str(CkHttpResponse::ckStatusCode(resp))
Debug CkHttpResponse::ckBodyStr(resp)
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
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": [
]
}