POST/ product-event-creation/ :custom_id/
Create product event (alternative)
There's an alternative endpoint for creating a product event assigned to a specific user.
If your products have custom IDs with "/" character, the standard endpoint will not work and you need to use the endpoint given below:
Attributes
Optional unless marked required
- user_id
- A unique identifier for the user which is given by User automatically.
- user_custom_id
- The unique identifier for the user which is provided by the client.
- custom_id
- A unique identifier for the product provided by the client.
- data
- A valid JSON object with additional data (attributes). Special "custom_data" key may contain additional custom json defined data unique per product event occurence.
- event_type
- A predefined event type. See the available types in What Is a Product Event.
- 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/product-event-creation/:custom_id/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"user_custom_id": "jane-doe",
"event_type": "purchase",
"timestamp": 1794303223,
"data": {
"quantity": 1
}
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/product-event-creation/:custom_id/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
user_custom_id: "jane-doe",
event_type: "purchase",
timestamp: 1794303223,
data: {
quantity: 1,
},
}),
},
);
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/product-event-creation/:custom_id/",
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_custom_id" => "jane-doe",
"event_type" => "purchase",
"timestamp" => 1794303223,
"data" => [
"quantity" => 1,
],
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/product-event-creation/:custom_id/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"user_custom_id": "jane-doe",
"event_type": "purchase",
"timestamp": 1794303223,
"data": {
"quantity": 1,
},
},
)
print(response.json())
Response examples
- 201 Created
- 404 Not Found
{
"id": 388
}
{
"detail": "Couldn't find product with custom_id = missing"
}
Response fields
Fields returned in the 201 Created response body.
- id
- ID of the product.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.