POST/ webpush-campaign/
Create webpush campaigns
You can create a webpush campaign.
Attributes
Optional unless marked required
- name
- A Webpush campaign name.
- segment
- A unique identifier for the user segment which is given by User automatically.
- messages
- A list of objects. Each object is a valid web push message (check out the Webpush Message attributes).
- eta
- A DateTime when the campaign should be sent. Delivery will start instantly if not provided.
- ttl
- 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
Optional unless marked required
- title
- A title of a web push message.
- body
- A content of a web push message.
- url
- A URL of a web push message.
- require_interaction
- A flag defining if a notification should remain active until the user clicks or dismisses it, rather than closing automatically.
- doughnut_title
- Action button 1 label.
- doughnut_url
- Action button 1 URL.
- coffee_title
- Action button 2 label.
- coffee_url
- Action button 2 URL.
- icon
- A URL of image inside a web push message.
- badge
- 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",
"segment": 12345,
"eta": "2026-11-17T13:25:29Z",
"ttl": 86400,
"messages": [
{
"title": "The spring sale has started",
"body": "Save up to 30% on outdoor gear.",
"url": "https://example.com/sale",
"require_interaction": false
}
]
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/webpush-campaign/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Spring sale push",
segment: 12345,
eta: "2026-11-17T13:25:29Z",
ttl: 86400,
messages: [
{
title: "The spring sale has started",
body: "Save up to 30% on outdoor gear.",
url: "https://example.com/sale",
require_interaction: false,
},
],
}),
},
);
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/webpush-campaign/",
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([
"name" => "Spring sale push",
"segment" => 12345,
"eta" => "2026-11-17T13:25:29Z",
"ttl" => 86400,
"messages" => [
[
"title" => "The spring sale has started",
"body" => "Save up to 30% on outdoor gear.",
"url" => "https://example.com/sale",
"require_interaction" => false,
],
],
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/webpush-campaign/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"name": "Spring sale push",
"segment": 12345,
"eta": "2026-11-17T13:25:29Z",
"ttl": 86400,
"messages": [
{
"title": "The spring sale has started",
"body": "Save up to 30% on outdoor gear.",
"url": "https://example.com/sale",
"require_interaction": False,
},
],
},
)
print(response.json())
Response examples
- 201 Created
- 400 Bad Request
{
"id": 1,
"name": "string",
"category": null,
"eta": "2026-01-01T12:00:00Z",
"ttl": 1,
"folder": null
}
{"name": ["This field is required."],"messages": ["This field is required."],"segment": ["This field is required."]}Response fields
Fields returned in the 201 Created response body.
- id
- A unique identifier for the campaign.
- name
- A Webpush campaign name.
- category
- Deprecated (replaced by folders). Read-only. Existing campaigns may return a legacy category value; new campaigns always return
null. Folder assignment will be available in the next API version. - eta
- A DateTime when the campaign is scheduled to be sent.
nullif sent immediately. - ttl
- Time-to-live in seconds.
- folder
- ID of the folder the campaign is in, or
null.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.