Skip to content
Home ยป API

API

https://billingdb.com/billingAPI.yaml

The Billing API is an API for managing billing information. It allows you to create, read, update, and delete invoices, as well as retrieve a list of all invoices.

Base URL

The base URL for the API is https://api.example.com/v1. All endpoints are relative to this URL.

Authentication

The Billing API requires authentication to access. You must include an API key with all requests. The API key should be included in the Authorization header as a Bearer token.

Example:

makefileCopy codeAuthorization: Bearer <API_KEY>

Invoices

Get all invoices

bashCopy codeGET /invoices

This endpoint returns a list of all invoices.

Parameters

None.

Responses

  • 200: The list of invoices.
  • 401: Authentication failed.
  • 403: The authenticated user does not have permission to access this endpoint.
  • 500: An error occurred on the server.

Example response

cssCopy code[  {    "id": 1,    "customer_id": 123,    "amount": 100.0,    "date": "2023-03-01",    "due_date": "2023-03-31"  },  {    "id": 2,    "customer_id": 456,    "amount": 50.0,    "date": "2023-03-15",    "due_date": "2023-04-15"  }]

Create a new invoice

bashCopy codePOST /invoices

This endpoint creates a new invoice.

Parameters

None.

Request body

The request body must contain a JSON object with the following fields:

  • customer_id (required): The ID of the customer associated with the invoice.
  • amount (required): The amount of the invoice.
  • date (required): The date the invoice was issued.
  • due_date (required): The due date of the invoice.

Responses

  • 201: The newly created invoice.
  • 400: The request body was invalid or missing a required field.
  • 401: Authentication failed.
  • 403: The authenticated user does not have permission to access this endpoint.
  • 500: An error occurred on the server.

Example request body

jsonCopy code{
  "customer_id": 123,
  "amount": 100.0,
  "date": "2023-03-01",
  "due_date": "2023-03-31"
}

Example response

jsonCopy code{
  "id": 1,
  "customer_id": 123,
  "amount": 100.0,
  "date": "2023-03-01",
  "due_date": "2023-03-31"
}

Get an invoice by ID

bashCopy codeGET /invoices/{id}

This endpoint returns an invoice with the specified ID.

Parameters

  • id (required): The ID of the invoice to retrieve.

Responses

  • 200: The invoice with the specified ID.
  • 401: Authentication failed.
  • 403: The authenticated user does not have permission to access this endpoint.
  • 404: The invoice with the specified ID was not found.
  • 500: An error occurred on the server.

Example response

jsonCopy code{
  "id": 1,
  "customer_id": 123,
  "amount": 100.0,
  "date": "2023-03-01",
  "due_date": "2023

Here’s a sample JSON response for a billing API invoice:

jsonCopy code{
  "id": "123456",
  "date": "2022-02-28T12:34:56Z",
  "due_date": "2022-03-14T00:00:00Z",
  "currency": "USD",
  "subtotal": 100.00,
  "tax": 10.00,
  "total": 110.00,
  "line_items": [
    {
      "id": "1",
      "description": "Product 1",
      "quantity": 2,
      "price": 50.00,
      "subtotal": 100.00
    }
  ],
  "customer": {
    "id": "789",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "address": {
      "street": "123 Main St",
      "city": "Anytown",
      "state": "CA",
      "zip": "12345",
      "country": "US"
    }
  },
  "status": "paid",
  "payment": {
    "id": "abcdefg12345",
    "date": "2022-03-01T12:34:56Z",
    "amount": 110.00,
    "method": "credit_card",
    "card": {
      "type": "Visa",
      "last4": "1234",
      "exp_month": 12,
      "exp_year": 2023
    }
  }
}

This is just a sample response, so you’ll need to modify it to fit your specific use case. In particular, you’ll need to update the invoice details to match your specific billing system and include any additional fields that your API requires.

Here’s a sample JSON request and response for a usage reporting API:

JSON Request:

jsonCopy code{
  "start_date": "2022-01-01",
  "end_date": "2022-01-31",
  "filters": {
    "region": "us-west-1",
    "service": "EC2"
  }
}

In this example, the request includes a start and end date range for the usage report, as well as filters to narrow the report down to a specific region and service.

JSON Response:

jsonCopy code{
  "start_date": "2022-01-01",
  "end_date": "2022-01-31",
  "filters": {
    "region": "us-west-1",
    "service": "EC2"
  },
  "usage": [
    {
      "resource_id": "i-1234567890abcdef0",
      "resource_name": "web-server-1",
      "service": "EC2",
      "region": "us-west-1",
      "start_time": "2022-01-01T00:00:00Z",
      "end_time": "2022-01-01T01:00:00Z",
      "duration": 3600,
      "cost": 0.50
    },
    {
      "resource_id": "i-0987654321fedcba0",
      "resource_name": "db-server-1",
      "service": "RDS",
      "region": "us-west-1",
      "start_time": "2022-01-01T00:00:00Z",
      "end_time": "2022-01-01T01:00:00Z",
      "duration": 3600,
      "cost": 1.00
    }
  ],
  "total_cost": 1.50
}