Skip to content

Document the contact segments API - #77

Draft
oshchyhol wants to merge 4 commits into
mainfrom
document-contact-segments
Draft

oshchyhol wants to merge 4 commits into
mainfrom
document-contact-segments

Conversation

@oshchyhol

Copy link
Copy Markdown
Contributor

Motivation

Document the new contact segments endpoints (list, show, create, update and delete) and the segment_id filter on GET /api/contacts.

Don't merge yet: merging publishes on docs.mailtrap.io. This merges once the endpoints are live, together with two upcoming fixes that the text already describes: not_within_last_day next to other conditions in a group, and campaign event dates (equal, less_than, between) when no campaign is picked.

Changes

  • a Contact Segments page under Contacts: how conditions work, the fields, an operator table per field type with the web app's labels, value formats, campaign event conditions and the validation messages
  • getContactSegments, getContactSegment, createContactSegment, updateContactSegment and deleteContactSegment, with schemas, examples and cURL samples (no SDK supports segments yet)
  • a segment_id parameter on getContacts, with its 422 examples
  • a RATE_LIMITED response (150 requests per 10 seconds per token) for the new operations; the other contacts operations keep LIMIT_EXCEEDED

How to test

Once the endpoints are live. Use an API token with admin access to an account that has contacts and a text contact field with the merge tag company.

Segments endpoints

  • POST /api/contacts/segments with the create example from the docs → 201 with the body from the docs
  • GET /api/contacts/segments → 200 with the new segment in data; ?per_page=1&token=2 → the second page
  • GET /api/contacts/segments/{id} → 200 with stats.contacts_count and stats.subscribed_contacts_count
  • PATCH /api/contacts/segments/{id} with {"conditions": [[{"name": "fields.company", "operator": "greater_than", "value": "a"}]]} → 422 with group 1, condition 1: operator is not allowed for this field
  • PATCH with {"name": "Acme customers"} → 200, conditions unchanged; with {"conditions": []} → 200 and "conditions": []
  • schedule a campaign with the segment as its audience, then DELETE /api/contacts/segments/{id} → 422 with the message from the docs; move the campaign back to draft, DELETE again → 204
  • with a read-only token, POST /api/contacts/segments → 403 with Access forbidden

Contacts list

  • GET /api/contacts?segment_id={id} → the segment's contacts, unsubscribed ones included; adding &status=subscribed → only the subscribed ones
  • ?segment_id=999999999 → 422 with not found; ?segment_id=abc → 422 with must be an integer

After merge, in the API reference (https://docs.mailtrap.io/developers)

  • Contacts → Contact Segments shows the five operations, and its tables and JSON blocks render
  • Contacts → "Get a list of contacts" shows the segment_id parameter and the new 422 examples
  • the other Contacts pages look as before

Images and GIFs

N/A

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A list_ids condition with more than 100 IDs is now refused with 422, so the Lists row and the list of condition messages say so.
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