> ## 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.

# Node.js Example

> Full integration example using the CrediBill HTTP API

This example demonstrates a full integration flow: initializing the client, creating a customer, and starting a subscription.

## Prerequisites

* Node.js v14+
* No SDK required — this example uses the CrediBill HTTP API via server-side requests (App Router)

## Full Script (API-first)

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

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

      // Server-side: call CrediBill API using secret key
      const response = 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),
        }
      );

      const data = await response.json();

      if (!response.ok) {
        return NextResponse.json({ error: data }, { status: response.status });
      }

      return NextResponse.json(data);
    }
    ```

    **Usage (server-side only):** POST JSON to `/api/demo/create-customer` with body:
    **Usage (server-side only):** POST JSON to `/api/demo/create-customer` with body:

    ```json theme={null}
    {
      "email": "customer@example.com",
      "name": "Startup Inc",
      "paymentMethod": "mobile_money_mtn",
      "paymentDetails": { "phoneNumber": "+256772123456" }
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    # Create a customer directly with the CrediBill API
    curl -X POST https://giant-goldfish-922.convex.site/api/customers \
      -H "Authorization: Bearer cb_live_abc123def456" \
      -H "Content-Type: application/json" \
      -d '{
        "email": "customer@example.com",
        "name": "Startup Inc",
        "paymentMethod": "mobile_money_mtn",
        "paymentDetails": { "phoneNumber": "+256772123456", "provider": "flutterwave" }
      }'
    ```
  </Tab>
</Tabs>

**Notes:**

* Prefer calling the CrediBill API from your server (App Router or serverless functions) so secret keys remain confidential.
* For frontend data fetching patterns, see the React + TanStack Query examples in other guides.
