Repository navigation
Add Subscription Topics and topic fields on campaigns, contacts, imports, suppressions, email logs and webhooks #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
44dd42d
c5c1e84
bade5c8
b50a8e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.mailtrap.examples.subscriptiontopics; | ||
|
|
||
| import io.mailtrap.api.subscriptiontopics.SubscriptionTopicListFilter; | ||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.exception.http.HttpClientException; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.response.subscriptiontopics.SubscriptionTopicListResponse; | ||
|
|
||
| public class SubscriptionTopicsExample { | ||
|
|
||
| private static final String TOKEN = System.getenv("MAILTRAP_API_KEY"); | ||
|
|
||
| public static void main(String[] args) { | ||
| final var config = new MailtrapConfig.Builder() | ||
| .token(TOKEN) | ||
| .build(); | ||
|
|
||
| final var client = MailtrapClientFactory.createMailtrapClient(config); | ||
|
|
||
| // The subscription topic endpoints are token-scoped: the account is resolved from the API token. | ||
| // They are read-only: topics are created and edited in the Mailtrap app. | ||
| final var subscriptionTopics = client.marketingApi().subscriptionTopics(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| final SubscriptionTopicListResponse page; | ||
| try { | ||
| // Topics by id, deleted ones left out. Pass null for the first page with API defaults. | ||
| page = subscriptionTopics.getSubscriptionTopics(SubscriptionTopicListFilter.builder().perPage(50).build()); | ||
| } catch (final HttpClientException e) { | ||
| if (e.getStatusCode() == 403) { | ||
| System.out.println("Subscription topics aren't available for this account or token"); | ||
| return; | ||
| } | ||
| throw e; | ||
| } | ||
|
|
||
| // A topic with a null domainId covers every sending domain. | ||
| page.getData().forEach(System.out::println); | ||
|
|
||
| // Pass the next token with the same perPage to get the next page. | ||
| if (page.getPagination().getNextToken() != null) { | ||
| System.out.println(subscriptionTopics.getSubscriptionTopics(SubscriptionTopicListFilter.builder() | ||
| .perPage(50) | ||
| .token(page.getPagination().getNextToken()) | ||
| .build()).getData()); | ||
| } | ||
|
|
||
| if (page.getData().isEmpty()) { | ||
| System.out.println("The account has no subscription topics yet"); | ||
| return; | ||
| } | ||
|
|
||
| // Get one topic by id. This also returns a topic deleted after a campaign was assigned it, with deletedAt set. | ||
| System.out.println(subscriptionTopics.getSubscriptionTopic(page.getData().get(0).getId()).getData()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package io.mailtrap.api.subscriptiontopics; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Pagination parameters for listing subscription topics. All fields are optional; | ||
| * {@code null} fields are omitted from the query string. | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking. In bade5c8 you made the all-args constructors private so that adding a field doesn't break callers' constructor signatures. This new class has a public |
||
| @Builder | ||
| public class SubscriptionTopicListFilter { | ||
|
|
||
| /** | ||
| * Number of topics per page (max 100, default 50). | ||
| */ | ||
| private Integer perPage; | ||
|
|
||
| /** | ||
| * Page number to retrieve (page-token pagination, default 1). | ||
| */ | ||
| private Integer token; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.