Skip to content

feat(account-tree): Add usage attribution types and attributed usage - #379

Open
lovrocolic wants to merge 3 commits into
mainfrom
usage_attribution
Open

lovrocolic wants to merge 3 commits into
mainfrom
usage_attribution

Conversation

@lovrocolic

Copy link
Copy Markdown
Collaborator

Context

Account tree MVP adds API endpoints for usage attribution types (getlago/lago-api#6415) and attributed usage (getlago/lago-api#6566).

Description

  • Add client.usage_attribution_types with create, get, update, destroy and get_all, keyed by code. An explicit parent_code: nil is sent so a type can be detached from its parent.
  • Add client.customers.attributed_usage(external_customer_id, external_subscription_id, options), which encodes filters and charge_codes as bracketed query params.

🤖 Generated with Claude Code

@vincent-pochet vincent-pochet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against the API (main) and the spec in getlago/lago-openapi#665. The first 3 block the merge: create can never succeed against the real API.

Comment thread lib/lago/api/resources/customer.rb Resolved
Comment thread lib/lago/api/resources/customer.rb Resolved
Comment thread lib/lago/api/resources/customer.rb Resolved
lovrocolic and others added 2 commits October 23, 2026 12:07
- Whitelist `attribution_keys` (array) and `description` instead of the
  singular `attribution_key`, matching the API strong params
- Use `hierarchical` role and the current serializer shape in fixtures
- `attributed_usage`: skip nil options, send empty `filters`/`charge_codes`
  arrays as empty selections, escape the customer external id and build
  the query through `connection.get_all`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
description: params[:description],
attribution_keys: params[:attribution_keys],
role: params[:role],
}.compact

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.compact drops an explicit description: nil, so update({ description: nil }, 'team') sends an empty payload and the old description stays (200, no error). The API clears it when the key is present (UpdateService uses params.key?(:description)). Could description follow the same key? pattern as parent_code?

result[:description] = params[:description] if params.key?(:description)

if filter_value.is_a?(Array)
query_params.concat(array_query_param("filters[#{filter_key}][]", filter_value))
else
query_params << ["filters[#{filter_key}]", filter_value]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With filters: { team: nil } this sends a valueless filters[team], so the API filters on a blank value instead of ignoring the key. Maybe skip nil inner values here (next if filter_value.nil?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants