# Connect Aiven

Costfluent reads your Aiven spend from the organization's invoices, through the Aiven API, with an
application token you create for it. One connection is one Aiven organization, and the cost of
every billing group, project and service in it.

## How Costfluent connects

Costfluent stores the application token encrypted and uses it to read the organization you name:
its invoices and their lines, and each billing group's name and payment type. The organization ID
you enter is the connection's identity, and the token is only ever used for that connection.

:::caution
The "View billing" permission that reads the invoices also reaches each billing group's contact
emails, addresses and VAT ID. Costfluent never reads them. Give the application user that one
permission and no other, create it for Costfluent alone, and give its token an expiry.
:::

## Prerequisites

1. The Owner or Integration owner organization role in Costfluent.
2. An Aiven application user for Costfluent alone, in the organization you connect. In the Aiven
   Console, open "Admin", then "Application users", and select "Create application user". Name it
   for Costfluent and give it the "View billing" permission and no other.
3. An application token of that user. Open the user and select "Generate token". Give the token the
   `billing:read` scope and a session duration of a year or less: the token stops working then, so
   note the date to replace it before. Copy the token before you leave that screen: Aiven shows it
   only once.
4. The organization ID, copied from the organization's settings in the Aiven Console, such as
   `org1234abcd`: 1 to 36 letters, digits, hyphens or underscores. It must be the organization the
   application user belongs to.

## Connect

<Stepper>

1. Open **Settings**, then **Integrations**, select **Aiven**, and open the **Connect** tab.
2. Select "Add application token", keep the suggested **Display name** or enter your own, and paste
   the token into **Application token** and the organization ID into **Organization ID**. Spaces
   around either value are removed.
3. Select "Test connection" to see each check, or "Connect" to save.

</Stepper>

Before storing anything, Costfluent reads the organization's invoice list with the token, so a
connection that saves can read your invoices. A second connection of the same organization is
refused.

## Data and freshness

Aiven invoices each billing group monthly, on the first day of the next month. Costfluent files every
row on the first day of its month. Month and longer views are exact; a daily chart shows the whole
month on its first day, and daily cost for Aiven is not available.

:::note
The running month has no invoice, so it shows no Aiven cost until Aiven issues that invoice on the
first of the next month. Each sync also reads the previous month again until the 15th of the month,
so an invoice issued on the first arrives with the next sync.
:::

:::note
Each billing group's amounts are in its own invoice currency: Aiven bills in AUD, CAD, CHF, DKK, EUR,
GBP, JPY, NOK, NZD, SEK, SGD or USD. Amounts are before tax. Credits are credit rows, and multiplier
and rounding lines are adjustments. An old invoice Aiven cannot itemize arrives as one row of its
total before tax.
:::

:::caution
A billing group paid through a cloud marketplace, with an AWS, Azure or Google Cloud subscription,
is not collected: its cost is already on that cloud's bill.
:::

Connecting imports as far back as your plan's backfill reaches, and at most six months
([Manage connections](/connect/manage-connections#how-it-behaves)), for each month Aiven has
invoiced.

## Reporting dimensions

- The billing account is the billing group, by its name and ID, and the billing period is the
  calendar month.
- **Sub-account** is the project. A line without a project, such as support, a credit or rounding,
  sits under its billing group.
- **Service** is the line's service, such as `Aiven for PostgreSQL`. A line that names no service
  type is `Support` for support, `Networking` for a charge naming no service, plan or service ID,
  and `Aiven` otherwise, as for a credit, a multiplier, rounding or a fee. An old invoice Aiven cannot
  itemize is `Aiven` too.
- **SKU** is the line's plan, and for a `Networking` line its description.
- **Region** is the line's cloud.
- **Resource** is the line's service ID.
- **Charge category** is Credit for a credit, Adjustment for a multiplier or rounding line, and
  Usage otherwise.
- The line's tags are kept as tags.

## Update or disconnect

### After connecting

The **Manage** tab lists the connection by its display name, with its organization ID. Open the gear
icon beside it to see whether the invoices are still readable, which workspaces the connection
feeds, and which months have been imported. **Run checks** runs the checks again on request.

### Rotating or removing access

Aiven does not rotate the token for you, and it stops working at the end of its session duration.
Before then, generate a new token for the same application user the same way, select
**Update credentials** on the connection page and paste it with the same organization ID; then
revoke the old token in the Aiven Console.

To retire the connection, remove it in Costfluent, then revoke its token in the Aiven Console.
Removing it erases the cost it imported
([Remove a connection](/connect/manage-connections#remove-a-connection)).

## Troubleshooting

- **An Aiven application token and the organization ID are required.** One of the two fields is
  empty. Paste both.
- **An Aiven organization ID is 1 to 36 letters, digits, hyphens or underscores, as the Aiven
  Console shows it in the organization's settings.** The organization ID field holds something
  else, such as the organization's name. Copy the ID from the organization's settings.
- **Aiven refused this application token: it is invalid or has expired. Generate a token with the
  billing:read scope for an application user with the View billing permission and paste it.** The
  token is wrong, has expired or was revoked. Generate a new token as the prerequisites describe and
  select **Update credentials**.
- **Aiven refused this application token for organization ... Check that the token has not expired,
  has the billing:read scope, and belongs to an application user with the View billing permission
  in that organization.** The message names the organization ID you entered. Check each cause:
  whether the token has expired, whether it has the `billing:read` scope, and whether its
  application user holds the "View billing" permission in that organization. Generate a new token
  as the prerequisites describe if one is wrong, and select **Update credentials**.
- **Aiven found no organization ... this token can read. Copy the organization ID from the
  organization's settings in the Aiven Console, and check that the token's application user holds
  the View billing permission there.** The organization ID is wrong, or the application user does
  not belong to it. Copy the ID again from the organization's settings.
- **Aiven refused the invoice list for this token (...).** Aiven refused the check with another
  status than the ones above, which the message names. Check the token and the organization ID,
  then try again; if Aiven keeps refusing, tell us through the
  [contact form](https://costfluent.com/contact), naming the message.
- **Aiven could not be reached to verify these credentials.** Aiven did not answer, or answered
  with an error of its own, whose detail the message names. Select **Run checks** later.
- **Aiven invoice ... does not add up**, on a collection: the lines of the invoice the message names
  do not reach its total. **Aiven billing group ... has two invoices beginning in ...**: the billing
  group the message names has two invoices for one month. The collection fails rather than invent
  the difference or count the month twice; tell us through the
  [contact form](https://costfluent.com/contact), naming the message.
