Skip to content

Add batch() method to CustomerIO track client#123

Merged
hownowstephen merged 2 commits intomainfrom
MESS-675_add-batch-api-support
May 7, 2026
Merged

Add batch() method to CustomerIO track client#123
hownowstephen merged 2 commits intomainfrom
MESS-675_add-batch-api-support

Conversation

@hownowstephen
Copy link
Copy Markdown
Contributor

@hownowstephen hownowstephen commented May 7, 2026

Summary

  • Adds batch() method to CustomerIO class wrapping POST /api/v2/batch
  • Accepts a list of operation dicts, each with type, action, identifiers, and action-specific fields
  • Validates that operations list is non-empty

Example

cio.batch([
    {
        "type": "person",
        "action": "identify",
        "identifiers": {"id": "1"},
        "attributes": {"name": "Alice"},
    },
    {
        "type": "person",
        "action": "event",
        "identifiers": {"id": "1"},
        "name": "purchase",
    },
])

Closes #96

Test plan

  • test_batch_call — verifies correct URL (/api/v2/batch), method (POST), auth, content-type, and body structure
  • Empty/None operations raises CustomerIOException
  • Full test suite passes (29 tests)
  • Lint passes

Note

Low Risk
Low risk: adds a new client method and corresponding unit test without altering existing request flows; main risk is incorrect endpoint/URL construction for non-default ports.

Overview
Adds a new CustomerIO.batch(operations) helper that posts a list of Track API v2 operations to POST /api/v2/batch, with a guard that rejects empty/None operation lists.

Introduces test_batch_call to assert the request method, auth header, content type, URL suffix, and payload shape, and to verify invalid inputs raise CustomerIOException.

Reviewed by Cursor Bugbot for commit 4ec6ce4. Bugbot is set up for automated code reviews on this repo. Configure here.

Wraps the v2 batch endpoint (POST /api/v2/batch) to send multiple
operations (identify, event, suppress, etc.) in a single request.
Useful for backfills and high-volume updates without hitting rate limits.

Closes #96
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d59db34. Configure here.

Comment thread customerio/track.py Outdated
The previous approach used str.replace on base_url which silently
produced the wrong URL when url_prefix was customized. Build from
self.host and self.port instead, matching setup_base_url pattern.
@hownowstephen hownowstephen mentioned this pull request May 7, 2026
@hownowstephen hownowstephen merged commit 844bd9c into main May 7, 2026
10 checks passed
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.

Add support for batch update, added in the V2 of the API

2 participants