> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickshops.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Subscriptions API — Quickshops Headless REST API

> Generate a Stripe billing portal URL so subscribers can manage their subscription, update payment details, or cancel via the Quickshops Headless API.

The Subscriptions endpoint generates a Stripe billing portal URL for a specific subscriber. You call this endpoint from your server, receive a URL, and redirect the subscriber's browser to the portal. From there they can cancel their subscription, update their payment method, or view billing history. This route requires a valid API key.

<Note>
  The `memberSessionId` is the session ID from your member authentication system that links the portal request to the correct subscriber in Quickshops. This value identifies which subscriber's billing portal to open — pass the session ID of the currently authenticated user.
</Note>

***

## Create billing portal session

Generates a Stripe billing portal URL for the subscriber identified by the given member session ID.

```
POST /subscription/portal
```

### Body parameters

<ParamField body="memberSessionId" type="string" required>
  The session ID of the authenticated member whose subscription portal you want to open. This must correspond to an active subscriber on the store.
</ParamField>

### Request

```bash theme={null}
curl -X POST https://api.quickshops.app/v1/subscription/portal \
  -H "Authorization: Bearer qk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{ "memberSessionId": "sess_01j..." }'
```

### Response

```json theme={null}
{
  "data": {
    "url": "https://billing.stripe.com/p/session/..."
  }
}
```

<ResponseField name="data.url" type="string" required>
  A Stripe billing portal URL. Redirect the subscriber's browser to this URL so they can manage their subscription.
</ResponseField>

### Redirecting the subscriber

Call this endpoint from your server-side handler using the authenticated subscriber's session ID. Return the URL to your frontend to perform the redirect. Keep your API key on the server.

```typescript theme={null}
// Server-side only (API route, server action, or loader)
import { qs } from "@/lib/quickshops";

const { data } = await qs.subscription.subscriptionCreatePortalSession({
  memberSessionId: currentUser.sessionId,
});
const url = data.url;

// Return the URL to your frontend so it can redirect the subscriber
return { portalUrl: url };
```

Then in your client-side code, redirect using the URL returned from your server:

```javascript theme={null}
// Client-side — after receiving the URL from your server endpoint
window.location.href = portalUrl;
```

After the subscriber finishes in the portal, Stripe redirects them to the return URL configured in your Quickshops dashboard.
