POST
/webpush-campaign/Create webpush campaigns
You can create a webpush campaign.
| Attributes | Type | Required | Description |
|---|---|---|---|
| name | string | yes | A Webpush campaign name. |
| segment | integer | yes | A unique identifier for the user segment which is given by User.com automatically. |
| messages | list | yes | A list of objects. Each object is a valid web push message (check out the Webpush Message attributes). |
| eta | string | no | A DateTime when the campaign should be sent. Delivery will start instantly if not provided. |
| ttl | integer | no | The number of seconds that a message may be stored if the user is not immediately available (Time To Live). Default: 259200 (3 days). |
| Message attributes | Type | Required | Description |
|---|---|---|---|
| title | string | yes | A title of a web push message. |
| body | string | yes | A content of a web push message. |
| url | string | no | A URL of a web push message. |
| require_interaction | boolean | no | A flag defining if a notification should remain active until the user clicks or dismisses it, rather than closing automatically. |
| doughnut_title | string | no | Action button 1 label. |
| doughnut_url | string | no | Action button 1 URL. |
| coffee_title | string | no | Action button 2 label. |
| coffee_url | string | no | Action button 2 URL. |
| icon | string | no | A URL of image inside a web push message. |
| badge | string | no | A URL of image inside a web push message (known as a Big photo). Only works on Windows. |
Request
- CURL
- JavaScript
- PHP
- Python
curl -X POST \
"https://<your_app_subdomain>.user.com/api/public/webpush-campaign/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"name": "Spring Sale Push",
"eta": "2026-04-01T12:00:00Z",
"ttl": 86400,
"messages": [
{
"title": "Spring Sale is Live!",
"body": "Up to 50% off selected items. Shop now!",
"url": "https://yoursite.com/sale",
"require_interaction": true,
"doughnut_title": "Shop Now",
"doughnut_url": "https://yoursite.com/sale",
"coffee_title": "Learn More",
"coffee_url": "https://yoursite.com/about-sale",
"icon": "https://yoursite.com/icon-192.png",
"badge": "https://yoursite.com/badge-512.png"
}
],
"segment": 1
}'
var data = JSON.stringify({
name: "Spring Sale Push",
eta: "2026-04-01T12:00:00Z",
ttl: 86400,
messages: [
{
title: "Spring Sale is Live!",
body: "Up to 50% off selected items. Shop now!",
url: "https://yoursite.com/sale",
require_interaction: true,
doughnut_title: "Shop Now",
doughnut_url: "https://yoursite.com/sale",
coffee_title: "Learn More",
coffee_url: "https://yoursite.com/about-sale",
icon: "https://yoursite.com/icon-192.png",
badge: "https://yoursite.com/badge-512.png"
}
],
segment: 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/webpush-campaign/");
xhr.setRequestHeader("Accept", "*/*; version=2");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Token <your_64_char_api_key>");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://<your_app_subdomain>.user.com/api/public/webpush-campaign/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode(array(
'name' => 'Spring Sale Push',
'eta' => '2026-04-01T12:00:00Z',
'ttl' => 86400,
'messages' => array(
array(
'title' => 'Spring Sale is Live!',
'body' => 'Up to 50% off selected items. Shop now!',
'url' => 'https://yoursite.com/sale',
'require_interaction' => true,
'doughnut_title' => 'Shop Now',
'doughnut_url' => 'https://yoursite.com/sale',
'coffee_title' => 'Learn More',
'coffee_url' => 'https://yoursite.com/about-sale',
'icon' => 'https://yoursite.com/icon-192.png',
'badge' => 'https://yoursite.com/badge-512.png'
)
),
'segment' => 1
)),
CURLOPT_HTTPHEADER => array(
'Accept: */*; version=2',
'Content-Type: application/json',
'Authorization: Token <your_64_char_api_key>'
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
import json
url = "https://<your_app_subdomain>.user.com/api/public/webpush-campaign/"
payload = json.dumps({
"name": "Spring Sale Push",
"eta": "2026-04-01T12:00:00Z",
"ttl": 86400,
"messages": [
{
"title": "Spring Sale is Live!",
"body": "Up to 50% off selected items. Shop now!",
"url": "https://yoursite.com/sale",
"require_interaction": True,
"doughnut_title": "Shop Now",
"doughnut_url": "https://yoursite.com/sale",
"coffee_title": "Learn More",
"coffee_url": "https://yoursite.com/about-sale",
"icon": "https://yoursite.com/icon-192.png",
"badge": "https://yoursite.com/badge-512.png"
}
],
"segment": 1
})
headers = {
'Accept': '*/*; version=2',
'Content-Type': 'application/json',
'Authorization': 'Token <your_64_char_api_key>'
}
response = requests.post(url, headers=headers, data=payload)
print(response.text)
Response
{
"id": 3,
"name": "Spring Sale Push",
"category": null,
"eta": "2026-04-01T12:00:00Z",
"ttl": 86400
}