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

# Quickstart

> Start billing your first customer in under 5 minutes

This guide will walk you through integrating CrediBill into your application. We'll obtain API keys from the dashboard, authenticate, and create your first customer.

## Prerequisites

Before you begin, make sure you have:

1. A Credibill account. [Sign up here](https://dashboard.credibill.tech/signup).
2. A live application created in the [Developer Dashboard](https://dashboard.credibill.tech/apps).
3. An API Key from the [Developer Dashboard](https://dashboard.credibill.tech/settings).

## 1. Setup API Access

Store your API key securely in your environment variables.

```bash theme={null}
# .env.local
CREDIBILL_SECRET_KEY=sk_live_abc123def456
```

All API requests use the base URL `https://giant-goldfish-922.convex.site/api/` and require the `Authorization` header:
CREDIBILL\_SECRET\_KEY=sk\_live\_abc123def456

```bash theme={null}
Authorization: Bearer sk_live_abc123def456
Content-Type: application/json
```

Authorization: Bearer sk\_live\_abc123def456

A **Customer** represents a business or individual that subscribes to your service.

<Tabs>
  <Tab title="React">
    ```tsx theme={null}
    import { useMutation } from "@tanstack/react-query";

    function CreateCustomerForm() {
      const createCustomerMutation = useMutation({
        mutationFn: async (customerData) => {

          const response = await fetch("https://giant-goldfish-922.convex.site/api/customers", {
              "Content-Type": "application/json",
            },
            body: JSON.stringify(customerData),
          });

          if (!response.ok) {
            throw new Error("Failed to create customer");
          const response = await fetch("https://giant-goldfish-922.convex.site/api/subscriptions", {

          return response.json();
        },
      });

      const handleSubmit = (e) => {
        e.preventDefault();
          const response = await fetch("https://giant-goldfish-922.convex.site/api/webhooks"), {

        createCustomerMutation.mutate({
          email: formData.get("email"),
          phone: formData.get("phone")
          first_name: formData.get("name"),
          last_name: formData.get("last_name")
          ,
        });
          }
      }
      };

      return (
        <form onSubmit={handleSubmit}>
          <input name="email" placeholder="Email" required />
          <input name="name" placeholder="Name" required />
          <input name="phoneNumber" placeholder="Phone (+256772123456)" required />
          <button type="submit" disabled={createCustomerMutation.isPending}>
            {createCustomerMutation.isPending ? "Creating..." : "Create Customer"}
          </button>

          {createCustomerMutation.isSuccess && (
            <p>Customer created: {createCustomerMutation.data.id}</p>
          )}

          {createCustomerMutation.isError && (
            <p>Error: {createCustomerMutation.error.message}</p>
          )}
        </form>
      );
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.credibill.io/v1/customers \
      -H "Authorization: Bearer sk_live_abc123def456" \
      -H "Content-Type: application/json" \
      -d '{
        "email": "jane@example.com",
        "name": "Jane Doe",
        "paymentMethod": "mobile_money_mtn",
        "paymentDetails": {
          "phoneNumber": "+256772123456",
          "provider": "flutterwave"
        }
      }'
    ```

    **Response:**

    ```json theme={null}
    {
      "id": "cust_abc123def456",
      "email": "jane@example.com",
      "name": "Jane Doe",
      "createdAt": 1703510400
    }
    ```
  </Tab>
</Tabs>

<Warning>
  Never expose your Secret API Key in client-side code. Always perform billing
  operations from your backend server. For client-side operations, use
  publishable keys.
</Warning>

## 3. Subscribe the Customer

Now, subscribe the customer to a plan. Ensure you have created a plan in your dashboard first.

<Tabs>
  <Tab title="React + TanStack Query">
    ```tsx theme={null}
    import { useMutation, useQueryClient } from "@tanstack/react-query";

    function SubscribeCustomerForm({ customerId }) {
      const queryClient = useQueryClient();

      const subscribeMutation = useMutation({
        mutationFn: async (subscriptionData) => {
          const response = await fetch(
            "https://api.credibill.io/v1/subscriptions",
            {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.REACT_APP_CREDIBILL_SECRET_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify(subscriptionData),
            }
          );

          if (!response.ok) {
            throw new Error("Failed to create subscription");
          }

          return response.json();
        },
        onSuccess: () => {
          // Invalidate and refetch customer data
          queryClient.invalidateQueries({ queryKey: ["customer", customerId] });
        },
      });

      const handleSubscribe = () => {
        subscribeMutation.mutate({
          customerId: customerId,
          planId: "plan_pro_monthly",
          trialDays: 14,
        });
      };

      return (
        <div>
          <button onClick={handleSubscribe} disabled={subscribeMutation.isPending}>
            {subscribeMutation.isPending
              ? "Creating Subscription..."
              : "Subscribe to Pro Plan"}
          </button>

          {subscribeMutation.isSuccess && (
            <p>Subscription created: {subscribeMutation.data.id}</p>
          )}

          {subscribeMutation.isError && (
            <p>Error: {subscribeMutation.error.message}</p>
          )}
        </div>
      );
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.credibill.io/v1/subscriptions \
      -H "Authorization: Bearer sk_live_abc123def456" \
      -H "Content-Type: application/json" \
      -d '{
        "customerId": "cust_abc123def456",
        "planId": "plan_pro_monthly",
        "trialDays": 14
      }'
    ```

    **Response:**

    ```json theme={null}
    {
      "id": "sub_abc123def456",
      "customerId": "cust_abc123def456",
      "status": "trialing",
      "trialEndsAt": 1704201600,
      "currentPeriodStart": 1703596800,
      "currentPeriodEnd": 1706188800
    }
    ```
  </Tab>
</Tabs>

## 4. Handle Webhooks (Optional)

Set up webhooks to receive real-time updates about payments and subscriptions.

<Tabs>
  <Tab title="React + TanStack Query">
    ```tsx theme={null}
    import { useMutation } from "@tanstack/react-query";

    function WebhookSetup() {
      const webhookMutation = useMutation({
        mutationFn: async (webhookData) => {
          const response = await fetch("https://api.credibill.io/v1/webhooks", {
            method: "POST",
            headers: {
              Authorization: `Bearer ${process.env.REACT_APP_CREDIBILL_SECRET_KEY}`,
              "Content-Type": "application/json",
            },
            body: JSON.stringify(webhookData),
          });

          if (!response.ok) {
            throw new Error("Failed to create webhook");
          }

          return response.json();
        },
      });

      const handleSetupWebhook = () => {
        webhookMutation.mutate({
          url: "https://your-app.com/webhooks/credibill",
          events: ["payment.success", "subscription.activated"],
          secret: "whsec_your_webhook_secret",
        });
      };

      return (
        <div>
          <button onClick={handleSetupWebhook} disabled={webhookMutation.isPending}>
            {webhookMutation.isPending ? "Setting up..." : "Setup Webhooks"}
          </button>

          {webhookMutation.isSuccess && <p>Webhook configured successfully!</p>}

          {webhookMutation.isError && <p>Error: {webhookMutation.error.message}</p>}
        </div>
      );
    }
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    # Register webhook endpoint
    curl -X POST https://api.credibill.io/v1/webhooks \
      -H "Authorization: Bearer sk_live_abc123def456" \
      -H "Content-Type: application/json" \
      -d '{
        "url": "https://your-app.com/webhooks/credibill",
        "events": ["payment.success", "subscription.activated"],
        "secret": "whsec_your_webhook_secret"
      }'
    ```
  </Tab>
</Tabs>

## Next Steps

You've successfully billed your first customer! Explore deeper into the platform:

* [Understand Concepts](/docs/concepts/organizations)
* [Set up Webhooks](/docs/webhooks)
* [Explore the API](/docs/api-reference/endpoints)
