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

# Partners in Billing

> Confine a partner's Billing credential to the customers, subscriptions, or invoices you choose, tell it how to name them, and read the refusals it receives.

A [partner](https://docs.lerian.studio/en/platform/access-manager/features/partners/overview) can read your billing with its own credential. In Billing, you confine that credential to a customer, to some subscriptions, or to some invoices. This page shows how to choose that scope, what it reaches, and what the partner receives when it goes outside it.

A partner only reads billing. Billing gives no partner any write, and nothing of its configuration.

Every Billing partner needs a scope.

> [!NOTE]
>
> Partners in Billing need billing-worker v1.9.0 or later. Earlier versions have no partner support.

## Step by step

***

**1. Choose the partner's billing items**

Billing has three restrictions. Use one of them per partner. The **API field** is the `field` of a scope entry; the Console shows the name in the first column.

| Restriction | API field | What the partner reaches | What is refused |
| - | - | - | - |
| **Customer** (one or more values) | `customerId` | The listed customers: reading the customer, and listing its subscriptions and its invoices. | Reading one subscription or one invoice by its ID, other customers, listings that do not filter by the customer, and the plans. |
| **Subscription** (one or more values) | `subscriptionId` | The listed subscriptions: reading the subscription and its current usage. | Other subscriptions, the subscription and invoice listings, the customer, and the invoices. |
| **Invoice** (one or more values) | `invoiceId` | The listed invoices: reading the invoice and downloading its PDF. | Other invoices, the invoice listing, the customer, and the subscriptions. |

The scope catalog lists the three Billing restrictions. Read it with [Retrieve a product's scope catalog](https://docs.lerian.studio/en/reference/platform/access-manager/retrieve-a-product-s-scope-catalog.md) for `billing-worker`.

Some rules apply to every scope:

* A request that does not name one of the partner's items is refused. For example, a partner confined to a customer cannot list invoices without filtering by that customer.
* A request that lists several customers in a query is refused when any of them is outside the scope.
* The partner reads only your own billing, whatever its scope names.

**2. Give the partner its permissions and scope**

Create the partner, or change it, in the [Console](https://docs.lerian.studio/en/platform/access-manager/features/partners/console.md) or with the [Identity API](https://docs.lerian.studio/en/platform/access-manager/features/partners/api.md). The product slug is `billing-worker`.

* Add one scope entry, with one or more values. Without it, Access Manager refuses the partner with `400` and `IDE-1060`.
* Check the resources and actions. The most you can give is what the Billing `editor` role holds in your tenant. Above that, Access Manager refuses with `IDE-1043`. For example, `catalog-versions` with `catalog-versions:read` is above that role.

A partner receives only these permissions, each one at the level of the item it reads:

| Resource | Action | Who may receive it |
| - | - | - |
| `customers` | `customers:read` | A partner confined to customers |
| `subscriptions` | `subscriptions:read` | A partner confined to customers or to subscriptions |
| `invoices` | `invoices:read` | A partner confined to customers or to invoices |

A permission whose item is wider than the scope is refused with `400` and `IDE-1056`. For example, `customers` with `customers:read` for a partner confined to a subscription. The plans (`plans` with `plans:read`) act on the whole tenant and are never given to a partner: Access Manager refuses with `400` and `IDE-1056`.

**3. Create its Billing application**

Create the partner's application with the product `billing-worker`. See [Create the partner's applications](https://docs.lerian.studio/en/platform/access-manager/features/partners/api.md#create-the-partners-applications) in the API guide, or [in the Console](https://docs.lerian.studio/en/platform/access-manager/features/partners/console.md#create-the-partners-applications). Send the client ID and the client secret to the partner through a secure channel.

**4. Tell the partner how to name its items**

On the routes the partner reaches, the item is in the path, so the partner sends nothing extra. Only the two listings name the customer in a query. Every value must be inside the partner's scope.

| Routes | Writes | Reads and routes by ID |
| - | - | - |
| Customer: `GET /v1/customers/{customerId}` | None: Billing gives partners no write | Path `customerId` |
| Subscriptions: `GET /v1/subscriptions`, `GET /v1/subscriptions/{subscriptionId}`, `…/usage` | None | Listing: query `customerId`, required for the partner. By ID and usage: path `subscriptionId` |
| Invoices: `GET /v1/invoices`, `GET /v1/invoices/{invoiceId}`, `…/download` | None | Listing: query `customerId`, required for the partner. By ID and download: path `invoiceId` |

> [!WARNING]
>
> A subscription or an invoice read by its ID does not name its customer. A partner confined to a customer is refused there: it reaches its subscriptions and invoices through the listings, filtered by its customer. To read one subscription or one invoice by its ID, confine the partner to that subscription or to that invoice.

These routes do not name a customer, a subscription, or an invoice, and are refused to every partner: `GET /v1/plans`, `GET /v1/plans/{planId}`, and every route of the catalog, the schedules, the deployment identity, and provisioning. Use an application of your own institution for those routes.

**5. Confirm that it works**

This check assumes the partner has the `customers` resource with the `customers:read` action on Billing, and a scope restricted to one customer. Use the partner's credential. Read the customer inside its scope. The answer is `200`:

```bash theme={null}
BILLING_BASE_URL="https://your-billing-host"              # your Billing base URL
BILLING_BEARER_TOKEN="paste-the-partner-access-token-here"
CUSTOMER_ID="paste-the-customer-id-in-the-scope-here"

curl -s -o /dev/null -w '%{http_code}\n' \
  -H "Authorization: Bearer ${BILLING_BEARER_TOKEN}" \
  "${BILLING_BASE_URL}/v1/customers/${CUSTOMER_ID}"
```

Send the same request with a customer outside the scope. The answer is `403` with code `BLW-0003`.

## If something fails

***

| Code | Status | What it means | What to do |
| - | - | - | - |
| `BLW-0003` | 403 | The request is outside the partner's permissions or outside its scope, it does not name the partner's item, or it comes from an address outside the partner's IP allowlist. | Check that the request names an item in the partner's scope, in the path or in the `customerId` query. Check also that the partner has the permission for that route, and its IP allowlist. |
| `BLW-0002` | 401 | The partner is suspended or outside its validity period, or the request carries no valid token. | Reactivate the partner, correct its validity, or send a new token. |

The answer does not say whether the permissions or the scope refused the request. This is on purpose: a partner cannot use a refusal to learn which customers, subscriptions, or invoices exist outside its scope.

For the refusals when you create or change a partner, see [Error codes](https://docs.lerian.studio/en/platform/access-manager/features/partners/api.md#error-codes) in the API guide.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.