Skip to content

Add App API customer, object, activity, and segment read methods - #81

Open
oke11o wants to merge 2 commits into
customerio:mainfrom
oke11o:app-api-customers-objects-activities-segments
Open

Add App API customer, object, activity, and segment read methods#81
oke11o wants to merge 2 commits into
customerio:mainfrom
oke11o:app-api-customers-objects-activities-segments

Conversation

@oke11o

@oke11o oke11o commented Jul 24, 2026

Copy link
Copy Markdown

Summary

APIClient currently only exposes the write/send side of the App API (SendEmail, SendPush, SendSMS, SendInApp, SendInboxMessage, TriggerBroadcast). This adds the read-side methods that the Node SDK's APIClient already covers:

  • Customers: SearchCustomers, GetCustomersByEmail, GetAttributes, GetCustomerActivities, GetCustomerMessages, GetCustomerRelationships, GetCustomerSegments, GetCustomerSubscriptionPreferences, GetCustomersAttributes (bulk), GetSubscriptionCenterToken
  • Objects: GetObjectAttributes, GetObjectRelationships, FindObjects, ListObjectTypes
  • Activities: ListActivities
  • Segments: ListSegments, CreateSegment, GetSegment, DeleteSegment, GetSegmentCustomerCount, GetSegmentMembership, GetSegmentUsedBy
  • Subscriptions: ListSubscriptionTopics, ListSubscriptionChannels

SearchCustomers and FindObjects take a composable filter (AudienceFilter/ObjectFilter, built via FilterBySegment/FilterByAttribute/FilterAnd/FilterOr/FilterNot and their ObjectFilter* counterparts) mirroring the Node SDK's AudienceFilter/ObjectFilter union types, flattened to a single struct since Go has no union types.

Notes on shapes

  • Request shapes are cross-checked against customerio-node's lib/api.ts/lib/types.ts.
  • Response shapes are cross-checked against the published App API OpenAPI spec. A few fields are documented inconsistently as string vs. integer across endpoints (or between schema and example) — e.g. object_type_id, a subscription topic's id. Those are decoded via json.Number rather than a fixed type so either representation round-trips.
  • GetCustomerMessages/GetCustomerActivities accept an IDType option (id/email/cio_id), matching the Node SDK — this lets a caller look a customer up by email directly instead of a separate search call first.
  • Endpoints without a documented example response (only a schema) are modeled from the schema field names/types as declared, flagged in code comments where relevant.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./...
  • golangci-lint run ./... (v2.11.3, matching this repo's CI)

Note

Low Risk
Additive SDK surface and shared HTTP helpers; segment delete is the only mutating new call, with validation and tests. No changes to existing send/auth paths.

Overview
Expands APIClient beyond send/trigger APIs with read-side Customer.io App API coverage aligned to the Node SDK: customer search and profiles, objects, workspace activities, segments (including create/delete), and subscription topic/channel listing.

Shared plumbing adds doJSON on APIClient (marshal/unmarshal plus configurable success statuses), a queryBuilder in url.go that omits zero-value query params, PaginationOptions, and composable AudienceFilter / ObjectFilter helpers for SearchCustomers and FindObjects. Several response fields use json.Number where the API inconsistently returns string vs integer IDs.

HTTP tests use a new apiServer helper that records request method, path, and body for assertions.

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

Ports the read-side App API endpoints that customerio-node's APIClient
already covers but this Go client didn't: customer search/lookup/messages/
activities/relationships/segments/subscription-preferences, bulk customer
attributes, the subscription center token endpoint, object attributes/
relationships/search, object type listing, cross-workspace activity
listing, segment management (list/create/get/delete/customer_count/
membership/used_by), and subscription topic/channel listing.

Request shapes are cross-checked against customerio-node's lib/api.ts and
lib/types.ts; response shapes against the published App API OpenAPI spec.
Fields the API documents inconsistently as string vs. integer across
endpoints (e.g. object_type_id, topic id) are decoded via json.Number
rather than a fixed Go type.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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

Reviewed by Cursor Bugbot for commit 2ad89c4. Configure here.

Comment thread subscriptions.go Outdated
The list subscription topics endpoint may return topic IDs as either a
JSON string or an integer, matching how SubscriptionTopicPreference.ID is
already decoded elsewhere in this package. Typing SubscriptionTopic.ID as
a plain int made ListSubscriptionTopics fail JSON unmarshaling on
string-encoded IDs. Use json.Number for consistent, lenient decoding.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant