Migrate from legacy webhooks to Events & Actions
Events & Actions replaced webhook configuration on the Admin Portal Keysets page. PubNub automatically migrated existing paid-plan webhooks when this change shipped, before 16 January 2024. Check whether a webhook you configured on the Keysets page for Presence, Mobile Push Notifications, or Message Persistence is already an event listener and action in Events & Actions. If it isn't, this guide moves it there and updates any code that parses the webhook payload for the current shape.
Before you start
Confirm you have:
- Admin Portal access to the keyset with the legacy webhook configured.
- An Events & Actions plan that covers your listener and action needs. The Free plan includes one listener with a webhook-only action; higher tiers raise those limits and add retries.
Migrate with an AI coding assistant
If you use an AI coding assistant, paste this prompt into it to update your webhook handlers. The prompt makes the assistant read this guide, list every handler that parses a PubNub webhook, and stop before it removes legacy payload parsing. Do the Admin Portal steps in Move your webhook to an event listener and action yourself.
Migrate this codebase's PubNub webhook handlers from legacy webhooks to the
Events & Actions payload shape.
1. Read the migration guide first:
https://www.pubnub.com/docs/migration-guides/legacy-webhooks.md
If the PubNub MCP server is connected, you can call get_general_migration_guide
instead. Where the guide and your own knowledge of PubNub disagree, follow the
guide and tell me.
2. Before you edit anything, list every HTTP handler that receives a PubNub
webhook for Presence, Mobile Push Notifications, or Message Persistence. Also
list every place that reads its fields, such as user_id or sub_key. Then show me a plan
and wait for my approval.
3. Ask me which of these webhooks already exist as an event listener with a
webhook action in Events & Actions. PubNub migrated paid-plan webhooks
automatically before 16 January 2024. Creating the rest is Admin Portal work
show all 32 linesMove your webhook to an event listener and action
- Create an event listener for the event you previously received by webhook, following Create an event listener.
- Add a webhook action to that listener with the same destination URL, following Create a Webhook action.
- Repeat for each legacy webhook you had configured and still want to receive.
Update your webhook payload parsing
The webhook payload shape changed. The current payload wraps records in a data array and includes a dataSchema field.
1{
2 "dataSchema": "pubnub.com/schemas/events/presence.user.channel.joined?v=1.0.0",
3 "data": [
4 {
5 "id": "a36773df-d828-4d40-99ab-26b8ebe46e41",
6 "channel": "Channel-Barcelona",
7 "userId": "Jack-device",
8 "occupancy": 2,
9 "data": {
10 "action": "join",
11 "timestamp": "1750065086",
12 "precise_timestamp": "1750065086809",
13 "occupancy": "2",
14 "uuid": "Jack-device"
15 },
show all 20 linesLegacy webhooks put one record at the top level and used snake_case keys such as user_id and sub_key. Read the current record from data[0], and use userId and subKey instead.
This example shows the Presence "user started subscription to channel" event. For every other event type, and for enveloped variants that add Events & Actions metadata, see Events & Actions payloads.
Update Mobile Push Notifications parsing
Legacy Push Webhooks sent the push error or device record at the top level, with snake_case keys such as sub_key. For example, a legacy device removal looked like this:
1{
2 "sub_key": "sub-c-e1559b02-3320-11ea-b686-76f717eaed2c",
3 "timestamp": "16007987966269679",
4 "platform": "apns2",
5 "action": "remove",
6 "device": "f3b26d22f3b26d22f3b26d22f3b26d22f3b26d22f3b26d22f3b26d22f3b26d22"
7}
To receive push errors and device removals through Events & Actions, create one listener for the Push error event type and one for Device removed, and pair both with a Webhook action. Set up Push Webhooks walks through the setup and shows the current payload for both events. That page turns the envelope on, so read each record from event.payload.data and use subKey instead of sub_key.
Related tasks
- Configure Events & Actions. Create the event listener that replaces your legacy webhook.
- Create a Webhook action. Add and configure the webhook action itself, including retries and custom headers.
- Forward push errors and device removals to your endpoint. Forward push errors and device removals through Events & Actions.
- Events & Actions payloads. The payload shape for every event type and envelope variant.
- Events & Actions. The event listener and action model, and plan availability.