POST
/products-by-id/:custom_id/product_event/Create product event
You can create a product event assigned to a specific user.
| Attributes | Type | Required | Description |
|---|---|---|---|
| user_id | integer | yes | A unique identifier for the user which is given by User.com automatically. |
| user_custom_id | string | yes | The unique identifier for the user which is provided by the client. |
| custom_id | string | no | A unique identifier for the product provided by the client. |
| data | json | yes | 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 | string | yes | A prefined event type. Find defined choices: https://docs.user.com/how-to-create-product-events/ |
| timestamp | timestamp | yes | 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/products-by-id/:custom_id/product_event/"
-H 'authorization: Token <your_64_char_api_key>'
-H 'content-type: application/json'
-d '{
"user_id": 431, // OR use user_custom_id
"event_type": "order",
"timestamp": 1426967129,
"data": {
"create attribute for product": "my value",
"custom_data": {
"custom attr": "json data"
}
}
}'
var data = JSON.stringify({
"user_id": 431, // OR use user_custom_id
"event_type": "order",
"timestamp": 1426967129,
"data": {
"create attribute for event's product": "my value",
"custom_data": {
"custom attr": "json data"
}
}
});
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/products-by-id/:custom_id/product_event/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("accept", "*/*; version=2");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/products-by-id/:custom_id/product_event/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"user_id\": 431, // OR use user_custom_id\n\t\"event_type\": \"order\",\n\t\"timestamp\": 1426967129,\n\t\"data\": {\n\t\t\"create attribute for event's product\": \"my value\",\n\t\t\"custom_data\": {\n\t\t\t\"custom attr\": \"json data\"\n\t\t}\n\t}\n}",
CURLOPT_HTTPHEADER => array(
"Accept: */*; version=2",
"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/products-by-id/:custom_id/product_event/"
payload = "{\n\t\"user_id\": 431, // OR use user_custom_id\n\t\"event_type\": \"order\",\n\t\"timestamp\": 1426967129,\n\t\"data\": {\n\t\t\"create attribute for event's product\": \"my value\",\n\t\t\"custom_data\": {\n\t\t\t\"custom attr\": \"json data\"\n\t\t}\n\t}\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)
Response
{
"id": 388
}