push

Subscribe to and receive push notifications when a server-side notification is received, via the Web Push API

Web Push API

Mastodon natively supports the Web Push APIarrow-up-right. You can utilize the same mechanisms for your native app. It requires running a proxy server that connects to Android’s and Apple’s proprietary notification gateways. However, the proxy server does not have access to the contents of the notifications. For a reference, see Mozilla’s web push serverarrow-up-right, or more practically, see:

Subscribe to push notifications

POST https://mastodon.example/api/v1/push/subscription

Add a Web Push API subscription to receive notifications. Each access token can have one push subscription. If you create a new subscription, the old subscription is deleted. Returns: PushSubscription OAuth: User token + push Version history: 2.4.0 - added

Headers

Name
Type
Description

Authorization

string

Bearer <user token>

Request Body

Name
Type
Description

subscription[endpoint]

string

Endpoint URL that is called when a notification event occurs.

subscription[keys][p256dh]

string

User agent public key. Base64 encoded string of public key of ECDH key using prime256v1 curve.

subscription[keys][auth]

string

Auth secret. Base64 encoded string of 16 bytes of random data.

data[alerts][follow]

boolean

Receive follow notifications?

data[alerts][favourite]

boolean

Receive favourite notifications?

data[alerts][reblog]

boolean

Receive reblog notifications?

data[alerts][mention]

boolean

Receive mention notifications?

data[alerts][poll]

boolean

Receive poll notifications?

Get current subscription

GET https://mastodon.example/api/v1/push/subscription

View the PushSubscription currently associated with this access token. Returns: PushSubscription OAuth: User token + push Version history: 2.4.0 - added

Headers

Name
Type
Description

Authorization

string

Bearer <user token>

Change types of notifications

PUT https://mastodon.example/api/v1/push/subscription

Updates the current push subscription. Only the data part can be updated. To change fundamentals, a new subscription must be created instead. Returns: PushSubscription OAuth: User token + push Version history: 2.4.0 - added

Headers

Name
Type
Description

Authorization

string

Bearer <user token>

Request Body

Name
Type
Description

data[alerts][follow]

boolean

Receive follow notifications?

data[alerts][favourite]

boolean

Receive favourite notifications?

data[alerts][reblog]

boolean

Receive reblog notifications?

data[alerts][mention]

boolean

Receive mention notifications?

data[alerts][poll]

boolean

Receive poll notifications?

Remove current subscription

DELETE https://mastodon.example/api/v1/push/subscription

Removes the current Web Push API subscription. Returns: none OAuth: User token + push Version history: 2.4.0 - added

Headers

Name
Type
Description

Authorization

string

Bearer <user token>

Last updated

Was this helpful?