Register a browser push subscription
- Path
/pushSubscriptions/{accessToken}- Auth
- Access token · browser or app, or in the URL path
const url = 'https://releva.ai/api/v0/pushSubscriptions/YOUR_ACCESS_TOKEN';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"context":{"deviceId":"demo-browser-device-0001","profile":{"id":"DEMO-CUSTOMER-1001","email":"maria@example.com"}},"subscription":{"endpoint":"https://push.example.com/send/demo-subscription-0001","expirationTime":null,"keys":{"p256dh":"BDemoP256dhKeyForDocsOnly000000000000000000000000000000000000000000000000000000000000","auth":"DemoAuthSecret0000000A"}}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://releva.ai/api/v0/pushSubscriptions/YOUR_ACCESS_TOKEN \ --header 'Content-Type: application/json' \ --data '{ "context": { "deviceId": "demo-browser-device-0001", "profile": { "id": "DEMO-CUSTOMER-1001", "email": "maria@example.com" } }, "subscription": { "endpoint": "https://push.example.com/send/demo-subscription-0001", "expirationTime": null, "keys": { "p256dh": "BDemoP256dhKeyForDocsOnly000000000000000000000000000000000000000000000000000000000000", "auth": "DemoAuthSecret0000000A" } } }'Stores a browser’s Web Push subscription (PushSubscription.toJSON()) for a device and links the device to
the profile. The Releva JS SDK calls it after the visitor allows notifications, when Releva.push is called
with the serviceWorkerUrl option; subscribe with the VAPID key from push.vapidPublicKey in the
Releva.push response. The access token goes in the path (no pre-flight); an authorization header, if
present, takes precedence. JSON or form-encoded (formPayload = base64 of the URI-encoded JSON).
Writes a pushNotificationSubscribe event, which can trigger campaigns.
Authorizations
Section titled “Authorizations”- None
- accessToken
Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The shop’s public access token (UUID). Ignored when an authorization header is sent.
Example
YOUR_ACCESS_TOKENRequest Bodyrequired
Section titled “Request Bodyrequired”object
object
Browser device id (SDK cookie rlv_p).
Used as deviceId when deviceId is missing.
Control-group bucket. Default 9999.
object
Your customer id.
International format with + and country code; normalised with the shop country code first.
object
A number (what some browsers return) is rejected with 400.
object
Example
{ "context": { "deviceId": "demo-browser-device-0001", "profile": { "id": "DEMO-CUSTOMER-1001", "email": "maria@example.com" } }, "subscription": { "endpoint": "https://push.example.com/send/demo-subscription-0001", "expirationTime": null, "keys": { "p256dh": "BDemoP256dhKeyForDocsOnly000000000000000000000000000000000000000000000000000000000000", "auth": "DemoAuthSecret0000000A" } }}object
Base64(encodeURIComponent(JSON.stringify(WebPushSubscriptionRequest))). What the JS SDK sends.
Example generated
formPayload=exampleResponses
Section titled “Responses”Accepted for asynchronous processing.
object
Example
{}Authentication or validation error.
object
Human-readable error. Several validation errors are joined with a space.
Examples
{ "message": "context is missing from request body"}{ "message": "The 'subscription' field is required."}{ "message": "The 'subscription.endpoint' field must be a valid URL."}{ "message": "The 'subscription.keys.auth' field is required."}{ "message": "The 'subscription.expirationTime' field must be a string."}{ "message": "The 'context.profile.email' field must be a valid e-mail."}{ "message": "context.profile.phoneNumber must be a valid telephone number starting with + and international code, e.g. +1. Got abc instead."}{ "message": "The 'context.group' field must be less than or equal to 9999."}{ "message": "formPayload is missing from request body"}{ "message": "The access token you provided is invalid."}{ "message": "Domain with the provided access token cannot be found."}The domain is disabled.
object
Human-readable error. Several validation errors are joined with a space.
Example
{ "message": "Domain is disabled. Please reach out to support@releva.ai to enable it."}Request body larger than 800 KB.
object
Human-readable error. Several validation errors are joined with a space.
Example
{ "message": "request entity too large"}Unexpected server error.
object
Human-readable error. Several validation errors are joined with a space.
Example
{ "message": "An internal error occurred."}