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

# cURL Example

> Integration using standard HTTP requests

This example shows how to perform the same flow using raw HTTP requests with cURL. This is useful for testing or for languages without an official SDK.

## 1. Create Customer

<Tabs>
  <Tab title="Next.js (App Router)">
    ```ts theme={null}
    // app/api/customers/route.ts
    import { NextResponse } from "next/server";

    export async function POST(request: Request) {
      const body = await request.json();
      const res = await fetch(
        "https://giant-goldfish-922.convex.site/api/customers",
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.CREDIBILL_SECRET_KEY}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify(body),
        }
      );
      return NextResponse.json(await res.json(), { status: res.status });
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://giant-goldfish-922.convex.site/api/customers \
      -H "Authorization: Bearer cb_test_..." \
      -H "Content-Type: application/json" \
      -d '{"email":"customer@example.com","name":"Startup Inc","paymentMethod":"mobile_money_mtn"}'
    ```
  </Tab>
</Tabs>

**Response:**

```json theme={null}
{
  "id": "cus_12345",
  "email": "customer@example.com",
  "name": "Startup Inc",
  "created": 1678900000
}
```

## 2. Create Subscription

Take the `id` from the previous response (e.g., `cus_12345`) and use it to create a subscription.

<Tabs>
  <Tab title="Next.js (App Router)">
    ```ts theme={null}
    // app/api/subscriptions/route.ts
    import { NextResponse } from "next/server";

    export async function POST(request: Request) {
      const body = await request.json();
      const res = await fetch(
        "https://giant-goldfish-922.convex.site/api/subscriptions",
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${process.env.CREDIBILL_SECRET_KEY}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify(body),
        }
      );
      return NextResponse.json(await res.json(), { status: res.status });
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://giant-goldfish-922.convex.site/api/subscriptions \
      -H "Authorization: Bearer cb_test_..." \
      -H "Content-Type: application/json" \
      -d '{"customerId":"cus_12345","planId":"plan_starter_monthly"}'
    ```
  </Tab>
</Tabs>

**Response:**

```json theme={null}
{
  "id": "sub_67890",
  "status": "active",
  "current_period_end": 1681578400,
  "customer": "cus_12345",
  "plan": {
    "id": "plan_starter_monthly",
    "amount": 2900
  }
}
```
