POST/ events/
Create event
You can create an event.
Attributes
Optional unless marked required
- user_id
- A unique identifier for the user which is given by User automatically. Previously: "client".
- data
- A valid json object with additional data.
- name
- An event name.
- timestamp
- A datetime when an event occured in UNIX format.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/events/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1892,
"name": "plan_upgraded",
"timestamp": 1794295277,
"data": {
"plan": "pro",
"seats": 10,
"source": "api"
}
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/events/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: 1892,
name: "plan_upgraded",
timestamp: 1794295277,
data: {
plan: "pro",
seats: 10,
source: "api",
},
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/events/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"user_id" => 1892,
"name" => "plan_upgraded",
"timestamp" => 1794295277,
"data" => [
"plan" => "pro",
"seats" => 10,
"source" => "api",
],
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/events/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"user_id": 1892,
"name": "plan_upgraded",
"timestamp": 1794295277,
"data": {
"plan": "pro",
"seats": 10,
"source": "api",
},
},
)
print(response.json())
Response examples
- 200 OK
- 400 Bad Request
{
"id": 86,
"created": true
}
{"errors": {"name": ["This field is required."]}}'created: true' means that this is first occurrence for created event
'created: false' means that there is at least one occurence for this event in database
Response fields
Fields returned in the 200 OK response body.
- id
- A unique identifier for the event which is given by User automatically.
- created
trueif the event was recorded.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.