Corsair
PluginsSpotify

Spotify Webhooks

All available Spotify webhook events

The Spotify plugin includes webhook infrastructure for handling Spotify events.

New to Corsair? Learn about webhooks and hooks.

Full Implementation: See the Spotify plugin source code.

Setup

app/api/webhook/route.ts
import { processWebhook } from "corsair";
import { corsair } from "@/server/corsair";

export async function POST(request: Request) {
    const headers = Object.fromEntries(request.headers);
    const body = await request.json();

    const result = await processWebhook(corsair, headers, body);
    return result.response;
}

Spotify webhooks are identified by the x-spotify-signature or spotify-webhook headers.

Available Webhooks

Spotify's current webhook support is limited. The plugin provides webhook infrastructure that fires when Spotify sends events to your endpoint.

For most Spotify integration use cases, the recommended approach is to poll the API on a schedule using a background job system:

inngest/functions.ts
// Poll currently playing track every minute
export const pollNowPlaying = inngest.createFunction(
    { id: "poll-spotify-now-playing" },
    { cron: "* * * * *" },
    async () => {
        const current = await corsair.spotify.api.player.getCurrentlyPlaying({}); 

        if (current.data?.is_playing) {
            console.log("Now playing:", current.data.item?.name);
        }
    }
);