Skip to content

ECO-600: Ecommerce Objects - #22

Merged
johnkelesidis merged 7 commits into
mainfrom
feature/eco-600-java-sdk
Nov 17, 2026
Merged

johnkelesidis merged 7 commits into
mainfrom
feature/eco-600-java-sdk

Conversation

@segunmailerlite

@segunmailerlite segunmailerlite commented Oct 28, 2026 •

Copy link
Copy Markdown

Why?

  • The Java SDK only had e-commerce models for automation triggers, so it couldn't reach shops, orders, variants or the revenue reports from the API - Ecommerce & Revenue project.

Changes

  • New ml.ecommerce() with shops, products, variants, categories, customers, orders, carts, cart items, imports and settings, using the SDK's retriever/builder pattern.
  • ecommerceReport() on campaigns, subscribers, automations and shops for revenue stats and attributed orders.

@segunmailerlite segunmailerlite self-assigned this Oct 28, 2026
@mailerlite-kritika

mailerlite-kritika Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Re-runViewConfidence Score: 5/5

[Medium risk] The change moves no dependency version, so no reach applies. It is additive public API under ml.ecommerce() and new ecommerceReport() methods, and a revert removes it, which puts the risk at medium rather than higher. The existing EcommerceShop, EcommerceCategory and EcommerceProduct classes gain date-parsing fields, which the review did not show were checked against ApiResource's parsing of missing or differently formatted dates, though the diff shows no defect there.

Findings

Earlier findings (4 dismissed)

Summary

Adds e-commerce resources and revenue reports to the Java SDK

The change adds ml.ecommerce() with shops, products, variants, categories, customers, orders, carts, cart items, imports and settings, all using the existing retriever/builder pattern. It also adds ecommerceReport() on campaigns, subscribers and shops, which share EcommerceReportRetriever. The commits since the last review make EcommerceRequest.addQueryParameter drop a parameter when its value is null (so shopId(null) clears it) and add a test for that. They also add the ecommerce field and Javadoc comments in MailerLite.

Flow
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["Caller uses ml.ecommerce()"] --> B["Pick resource: shops, products, orders, carts, etc."]
B --> C["Retriever or builder creates request"]
C --> D["EcommerceApi sends request with URL-encoded query; null values dropped"]
D --> E["MailerLite e-commerce API"]
F["ecommerceReport() on campaigns, subscribers, automations, shops"] --> G["EcommerceReportRetriever"]
G -->|"stats() or orders()"| D
Loading

What's good

  • A single EcommerceRequest base class URL-encodes query parameters, and the tests assert the encoded form of the request URLs.
  • The tests capture each request's method, URL and body without calling the network, so they cover the whole endpoint surface.
  • Update calls drop fields the API does not accept on updates, such as items for carts and customer/cart for orders, and the tests check this.
Review context · 0/5 commands
  • Commands run: none

Reviews (6) · Last reviewed commit: "ECO-600: Drop e-commerce query parameter..." · claude-sonnet-5-5

@johnkelesidis

Copy link
Copy Markdown
Collaborator

@segunmailerlite fix the conflicts please

Keep both the ecommerce report methods and main's new automation and subscriber endpoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread README.md Resolved
Restore README whitespace so the diff holds only the e-commerce docs, and add Javadoc to the ecommerce report methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@johnkelesidis johnkelesidis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this! I reviewed the request side against the API source: paths, field names and import shapes (root arrays for products, categories and customers; {"orders": [...]} for orders) all match, and the full suite passes (120 tests, 0 failures).

The main blocker is the conversion_rate type in EcommerceStats, which makes both stats() calls throw on every real response. The tests don't catch it because every stubbed body is {}. The other comments are lower-severity bugs, duplication with existing models, and test gaps. Details inline.

*/
public abstract class EcommerceRequest<T extends EcommerceRequest<T>> extends PaginatedRequest<T> {

private Map<String, String> queryParameters = new LinkedHashMap<String, String>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bug: removeQueryParameter() does nothing on e-commerce retrievers. This class keeps its own queryParameters map and overrides add/get, but not ApiRequest.removeQueryParameter. So retriever().limit(10) followed by removeQueryParameter("limit") still sends ?limit=10.

More broadly, this forks query-string building (insertion order, key encoding, no bare ?) away from ApiRequest, which every other retriever still uses. Fixing ApiRequest.getQueryParameters() once (LinkedHashMap, encode keys, return "" when empty) would fix all callers and remove the need for this subclass.

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.

Fixed: EcommerceRequest now overrides removeQueryParameter, with a test.

I tried the broader fix in ApiRequest.getQueryParameters() (LinkedHashMap, encoded keys, no bare ?), but it broke 33 existing tests. The VCR fixtures are keyed on the exact request URL, so the trailing ? and the param order change every cassette hash, and we can’t re-record them without a live account. I’d rather keep the fork in EcommerceRequest for now and move it into ApiRequest in a separate PR when the fixtures can be re-recorded.

return EcommerceApi.create(apiObjectReference).postRequest(EcommerceApi.shopPath(shopId, "/orders"), EcommerceApi.json(builderBody), SingleOrder.class);
}

public SingleOrder update(String orderId) throws MailerLiteException

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bug: update with the builder's usual setters returns 422. create() and update() send the same body, but EcommerceUpdateOrderRequest marks customer and cart as prohibited. So builder().customer(c).item(i).status("complete").update("9") fails. CartBuilder.update() has the same problem with items (EcommerceUpdateCartRequest). Either strip those fields on update or document that update only accepts a subset.

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.

Fixed: order update() now strips customer and cart, and cart update() strips items, so the body matches the update request rules. I added tests for both that set those fields and check they aren’t sent.

public Boolean enableResubscribe;

@SerializedName("group")
public Group group;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bug (minor): group dates are never parsed. parseDates() / postDeserialize() is never called on this nested Group, so shop.group.createdAt is always null.

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.

Fixed: EcommerceShop now extends ApiResource and overrides parseDates() to also parse group. SingleShop and ShopsList call it from postDeserialize(). The new test checks that shops[0].group.createdAt gets parsed.

@SerializedName("stage")
public String stage;

@SerializedName("created_at")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Dates (created_at, updated_at, completed_at) are raw Strings here and across the new models. The rest of the SDK uses xxxStr + @ParseDate Date (via ApiResource/postDeserialize), as in Group, Automation and OrderActivity. Worth matching that so callers get java.util.Date consistently.

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: shop, category, product and order dates now use xxxStr + @ParseDate Date. The single and list responses call parseDates() from postDeserialize(), and nested objects get parsed too (shop group, product categories, the order’s customer and cart items). There’s a test that checks the order, product and category dates come back non-null.

return api;
}

static String json(Object body)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This builds a new GsonBuilder/Gson with the same exclusion strategies on every request, duplicating JsonBody.toJson / SdkGson.plain(). Suggest return JsonBody.toJson(body);.

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: EcommerceApi.json() now returns JsonBody.toJson(body). The new jsonWithout() helper for the update bodies uses SdkGson.plain() too.

@johnkelesidis johnkelesidis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please check comments

@johnkelesidis

Copy link
Copy Markdown
Collaborator

@segunmailerlite can you check the conflicts on this please?

massivebrains and others added 2 commits November 12, 2026 12:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the ApiRequest change from main, where a null value removes the parameter instead of failing in URLEncoder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@johnkelesidis
johnkelesidis merged commit da3a169 into main Nov 17, 2026
4 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.

3 participants