Create event using user custom ID
Events could be used in many ways, for example if you have e-commerce shop - you could bind that event to certain button, lets say it is Add to cart button, then pass data through that event.
POST
/users-by-id/:user_id/events/
Data
Type
Description
user_id
string
Your user custom ID
name
string
The name of newly created event
timestamp
timestamp
Date when this event was performed in UNIX format
data
array
Additional data
curl -X POST -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
"name":"profile_updated",
"timestamp": 1426967129,
"data":{
"keyData1":"value for key data 1"
}
}' "https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/"
Response
{
"id": 86,
"created": true
}
Note:
'created: true'
means that this is first occurrence for for created event'created: false'
means that there is at least one occurence for this event in database
var settings = {
"async": true,
"crossDomain": true,
"url": "https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/",
"method": "POST",
"headers": {
"authorization": "Token <your_64_char_api_key>",
"content-type": "application/json"
},
"processData": false,
"data": "{\r\n \"name\":\"profile_updated\",\r\n \"name\":1426967129,\r\n \"data\":{\r\n \"keyData1\":\"value for key data 1\"\r\n }\r\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
var data = JSON.stringify({
"name": "profile_updated",
"timestamp": 1426967129,
"data": {
"keyData1": "value for key data 1"
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
var request = require("request");
var options = { method: 'POST',
url: 'https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/',
headers:
{ 'content-type': 'application/json',
authorization: 'Token <your_64_char_api_key>' },
body:
{ name: 'profile_updated',
timestamp: 1426967129,
data: { keyData1: 'value for key data 1' } },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"name\":\"profile_updated\",\r\n \"name\":1426967129,\r\n \"data\":{\r\n \"keyData1\":\"value for key data 1\"\r\n }\r\n}",
CURLOPT_HTTPHEADER => array(
"authorization: Token <your_64_char_api_key>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
url = "https://<your_app_subdomain>.user.com/api/public/users-by-id/:user_id/events/"
payload = "{\r\n \"name\":\"profile_updated\"\r\n \"name\":1426967129 \r\n \"data\":{\r\n \"keyData1\":\"value for key data 1\"\r\n }\r\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
import http.client
conn = http.client.HTTPSConnection("<your_app_subdomain>.user.com")
payload = "{\r\n \"name\":\"profile_updated\",\\r\n \"name\":1426967129,\\r\n \"data\":{\r\n \"keyData1\":\"value for key data 1\"\r\n }\r\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
conn.request("POST", "/api/public/users-by-id/:user_id/events/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))