Integrations
Stripe
Sync Stripe billing events, payments, and subscription data with Amarsia.
Overview
The Stripe integration forwards Stripe webhook events to Amarsia, where they are stored as resources and events. This lets you query billing history, trigger workflows, and correlate payment activity with other data in your workspace.
Prerequisites
- An Amarsia workspace with a live API key (
sk_live_...) - A Stripe account with webhook configuration access
- Your server needs to be publicly accessible (or use a tunnel like ngrok for local development)
Step 1 — Install the Stripe SDK
npm install stripeStep 2 — Create a webhook handler
Create an endpoint in your application that receives Stripe events and forwards them to Amarsia:
// app/api/stripe-webhook/route.ts
import Stripe from 'stripe';
import { NextRequest, NextResponse } from 'next/server';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(request: NextRequest) {
const body = await request.text();
const signature = request.headers.get('stripe-signature')!;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET!
);
} catch {
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
}
// Forward to Amarsia
await fetch('https://api.amarsia.com/v1/events', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AMARSIA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: `stripe.${event.type}`,
payload: event.data.object,
}),
});
return NextResponse.json({ received: true });
}Step 3 — Configure the Stripe webhook
- Go to your Stripe Dashboard → Webhooks.
- Click Add endpoint.
- Enter your handler URL (e.g.
https://yourapp.com/api/stripe-webhook). - Select the events to listen for (start with
payment_intent.*andcustomer.subscription.*). - Copy the Signing secret and save it as
STRIPE_WEBHOOK_SECRETin your environment.
Step 4 — Set environment variables
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
AMARSIA_API_KEY=sk_live_...Verification
Once configured, trigger a test event from the Stripe dashboard and confirm it appears in your Amarsia workspace under Events.