Skip to content

Add ExcludedCustomer resource and exclude option on Customer.destroy (PIP-585) - #147

Open
ya-petrov-evgeniy wants to merge 2 commits into
mainfrom
evgenii/excluded-customers
Open

ya-petrov-evgeniy wants to merge 2 commits into
mainfrom
evgenii/excluded-customers

Conversation

@ya-petrov-evgeniy

@ya-petrov-evgeniy ya-petrov-evgeniy commented Nov 25, 2026 •

Copy link
Copy Markdown

Background

The ChartMogul API can now exclude customers from re-import and manage the exclude list (platform#33735, platform#33795, PIP-585):

  • DELETE /v1/customers/:uuid accepts an optional exclude boolean that also adds the customer to the account's exclude list.
  • GET /v1/excluded_customers lists excluded data source customers, newest first, with cursor pagination.
  • DELETE /v1/excluded_customers/:uuid re-includes a customer and responds 202 with customer_uuid and status (reimporting or manual_reimport_required).

Changes

  • Customer.destroy(config, uuid=..., exclude=True) sends exclude=true as a query param. Without exclude the request is unchanged and still returns None.
  • New ExcludedCustomer resource:
    • ExcludedCustomer.all(config, cursor=..., per_page=...) returns ExcludedCustomers(entries, has_more, cursor). Each entry has customer_uuid, data_source_uuid, external_id, name, email and excluded_at (parsed as a datetime).
    • ExcludedCustomer.reinclude(config, uuid=...) returns a ReincludedCustomer with only customer_uuid and status. List entries don't carry status. ReincludedCustomer overrides _load because Resource._load drops the body of a 202 response.
    • The method and type names match the other SDKs.
  • README examples for both.

Usage

chartmogul.Customer.destroy(config, uuid='cus_...', exclude=True).get()

page = chartmogul.ExcludedCustomer.all(config, per_page=50).get()
page.entries[0].excluded_at, page.cursor, page.has_more

result = chartmogul.ExcludedCustomer.reinclude(config, uuid='cus_...').get()  # ReincludedCustomer
result.status  # "reimporting" or "manual_reimport_required"

Backwards compatibility

Change Breaking?
exclude kwarg on Customer.destroy No. It's optional and the request is unchanged without it
New ExcludedCustomer and ReincludedCustomer classes No. They're new classes

Test plan

  • Customer.destroy with exclude=True sends ?exclude=true. This uses a case-sensitive mock so the bool-to-string conversion is checked.
  • Customer.destroy without exclude sends no query string.
  • ExcludedCustomer.all forwards cursor/per_page and parses the entries plus cursor/has_more.
  • ExcludedCustomer.all entries have no status attribute.
  • ExcludedCustomer.reinclude returns a ReincludedCustomer with customer_uuid/status from the 202 body.
  • Re-including a customer that isn't excluded (404) raises APIError.
  • python -m unittest: 215 tests pass. flake8 ./chartmogul is clean.
  • Mutation-checked: dropping the Customer.destroy override, removing exclude from _bool_query_params, removing the _load override, parsing the re-include result as ExcludedCustomer, putting status back on list entries, dropping raise_for_status, always sending exclude, and changing the path or schema each fail at least one new test.
  • Tested end-to-end against a local API (platform main with #33735 and #33795, exclude customers flag on) using a throwaway script. It creates two customers, deletes one with exclude=True and one without, pages through ExcludedCustomer.all(per_page=1) by cursor, and checks that only the excluded customer is listed, with all its fields. Re-including it with ExcludedCustomer.reinclude returns a ReincludedCustomer with manual_reimport_required (custom source), a second re-include raises APIError (404), and the customer is no longer listed.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ya-petrov-evgeniy
ya-petrov-evgeniy marked this pull request as ready for review November 25, 2026 08:25
Comment thread README.md Outdated
chartmogul.ExcludedCustomer.all(config, cursor='aabbcc', per_page=20)
# Removes the customer from the exclude list; the result has customer_uuid and
# status ('reimporting' or 'manual_reimport_required')
chartmogul.ExcludedCustomer.destroy(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb')

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.

I guess we could use reinclude here too for consistency across SDK.

@ya-petrov-evgeniy ya-petrov-evgeniy Nov 25, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, renamed to reinclude and it now returns a separate ReincludedCustomer with only customer_uuid and status.

…type

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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