Looking for detailed SDK documentation? Check out our SDK documentation for comprehensive guides on @flowglad/nextjs, @flowglad/react, @flowglad/express, and more.
1. Sign Up For Flowglad
Create a Flowglad account.2. Add Your API Key
Add your Flowglad API key to your environment.env
3. Install Flowglad
4. Server Setup
First, set up a Flowglad server factory function. Do this in a file that can be imported wherever you need to access billing data, or make calls to Flowglad.utils/flowglad.ts
Important:
B2B apps: Pass
customerExternalId is the ID from your app’s database (e.g., user.id or organization.id), not Flowglad’s customer ID.B2C apps: Pass user.id as customerExternalIdB2B apps: Pass
organization.id or team.id as customerExternalId/api/flowglad/[...path]. Your app will use this to send and receive data from Flowglad.
app/api/flowglad/[...path]/route.ts
The
getCustomerExternalId function extracts the customer ID from your app’s database (via your authentication system). Flowglad doesn’t care how you authenticate—just return the ID from your system that represents the billing entity (user ID for B2C, organization ID for B2B). This is not Flowglad’s customer ID.You can mount Flowglad’s handler at a different route, but you’ll
need to specify it via the
serverRoute prop in <FlowgladProvider /> in your React app.5. Set up React
Next, you need to set up the FlowgladProvider component.6. useBilling
Use the useBilling hook to get billing data on your customer’s frontend.