From 5b404b56306b48b4856fdf0466014875f68ec115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Martty?= Date: Wed, 11 Nov 2026 16:33:42 +0100 Subject: [PATCH 1/2] feat: return the rejected attributes of block writes The API now removes the attributes and the mobile keys that a block type does not declare, and adds "rejected" to the response of a block insert, a block update and a block validation. SingleEmailBlock had no field for it, so Gson dropped it. SingleEmailBlock now has a nullable rejected field of the existing EmailRejected type. The Javadoc of EmailValidation no longer says that only the settings validation has rejected. Co-Authored-By: Claude Opus 5.5 --- README.md | 16 +++++- .../mailerlite/sdk/emails/EmailRejected.java | 9 ++- .../sdk/emails/EmailValidation.java | 4 +- .../com/mailerlite/sdk/emails/Emails.java | 13 +++++ .../sdk/emails/SingleEmailBlock.java | 7 +++ .../com/mailerlite/sdk/tests/EmailsTest.java | 55 +++++++++++++++++++ .../sdk/tests/ReadmeExamplesTest.java | 4 +- .../email_block_created_rejected.json | 15 +++++ .../email_block_updated_rejected.json | 16 ++++++ .../email_block_validation_rejected.json | 9 +++ 10 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/responses/email_block_created_rejected.json create mode 100644 src/test/resources/responses/email_block_updated_rejected.json create mode 100644 src/test/resources/responses/email_block_validation_rejected.json diff --git a/README.md b/README.md index 092b079..7648ff4 100644 --- a/README.md +++ b/README.md @@ -1146,6 +1146,8 @@ Without `placement`, the API puts the block at the end of the email. The positio A `null` block throws `NullPointerException`, and the SDK sends no request. +The API removes the attributes and the `mobile` keys that the block type does not declare, and the insert is still a success. Then the response has `rejected` with the paths of these values, for example `editor_content.attrs.onclick`. Otherwise `rejected` is `null`. Only `createBlock` and `updateBlock` fill `rejected`. `getBlock` and `moveBlock` leave it `null`. + ```java // import .... @@ -1174,6 +1176,11 @@ class Example { System.out.println(blockId + " " + etag); + if (response.rejected != null) { + + System.out.println(String.join(", ", response.rejected.keys)); + } + } catch (MailerLiteException e) { e.printStackTrace(); @@ -1186,6 +1193,8 @@ class Example { The new `editorContent` replaces the whole content of the block. The API removes the keys that you do not send. So get the block, change its `editorContent`, and send all of it. The type and the position of the block do not change. +The API removes the attributes and the `mobile` keys that the block type does not declare, and the update is still a success. Then the response has `rejected` with the paths of these values. Otherwise `rejected` is `null`. + ```java // import .... @@ -1206,6 +1215,11 @@ class Example { System.out.println(response.etag); + if (response.rejected != null) { + + System.out.println(String.join(", ", response.rejected.keys)); + } + } catch (MailerLiteException e) { e.printStackTrace(); @@ -1268,7 +1282,7 @@ class Example { ### Validate a block -Checks a block before you insert it, and saves nothing. It needs no email and no etag. An invalid block is not an error: the response has `valid` set to `false` and the `errors` for each field. A `null` block sends an empty body. +Checks a block before you insert it, and saves nothing. It needs no email and no etag. An invalid block is not an error: the response has `valid` set to `false` and the `errors` for each field. If the block is valid and an insert would remove attributes, `rejected` has their paths. A `null` block sends an empty body. ```java diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java b/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java index bd7569e..8048de6 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java @@ -10,7 +10,10 @@ import com.google.gson.annotations.SerializedName; /** - * The unsafe values that the API removed or replaced. The request is still a success. + * The values that the API removed or replaced. The request is still a success. + *

+ * For settings, these are unsafe values. For a block, these are the attributes and the mobile keys that the block + * type does not declare. */ public class EmailRejected { @@ -18,7 +21,9 @@ public class EmailRejected { @SerializedName("message") public String message; - /** The paths of the values, for example "footer.social_links[0].url". */ + /** + * The paths of the values, for example "footer.social_links[0].url" or "editor_content.attrs.onclick". + */ @SerializedName("keys") public String[] keys; } diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java b/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java index ba1c939..5d313a6 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java @@ -33,7 +33,9 @@ public class EmailValidation extends MailerLiteResponse { public EmailSchema schema; /** - * The unsafe values that an update would remove, or null if there are none. Only the validation of settings has it. + * The values that the write would remove, or null if there are none. The API sends it only when valid is true. + * For settings, these are unsafe values. For a block, these are the attributes and the mobile keys that the + * block type does not declare. */ @SerializedName("rejected") public EmailRejected rejected; diff --git a/src/main/java/com/mailerlite/sdk/emails/Emails.java b/src/main/java/com/mailerlite/sdk/emails/Emails.java index c0aebb6..33dd933 100644 --- a/src/main/java/com/mailerlite/sdk/emails/Emails.java +++ b/src/main/java/com/mailerlite/sdk/emails/Emails.java @@ -103,6 +103,9 @@ public SingleEmailBlock getBlock(String emailId, String blockId) throws MailerLi *

* Without a placement, the API puts the block at the end of the email. The response has the new block with * its placement and the new etag. + *

+ * The API removes the attributes and the mobile keys that the block type does not declare, and the insert is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param etag the etag from the last response for the email @@ -121,6 +124,9 @@ public SingleEmailBlock createBlock(String emailId, String etag, EmailBlockInput *

* Without a placement, the API puts the block at the end of the email. The response has the new block with * its placement and the new etag. + *

+ * The API removes the attributes and the mobile keys that the block type does not declare, and the insert is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param etag the etag from the last response for the email @@ -144,6 +150,9 @@ public SingleEmailBlock createBlock(String emailId, String etag, EmailBlockInput *

* The new editor content replaces the whole content of the block. The API removes the keys that you do not * send. Read the block, change it, and send the full editor content. + *

+ * The API removes the attributes and the mobile keys that the block type does not declare, and the update is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param blockId the block ID @@ -163,6 +172,9 @@ public SingleEmailBlock updateBlock(String emailId, String blockId, String etag, *

* The new editor content replaces the whole content of the block. The API removes the keys that you do not * send. Read the block, change it, and send the full editor content. + *

+ * The API removes the attributes and the mobile keys that the block type does not declare, and the update is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param blockId the block ID @@ -267,6 +279,7 @@ public SingleEmailBlock moveBlock(String emailId, String blockId, String etag, E * Checks a block with the rules of an insert, and saves nothing. It needs no email and no etag. *

* An invalid block is not an error: the response has valid set to false and the errors for each field. + * If the block is valid and an insert would remove attributes, rejected has their paths. * * @param block the block to check. A null block sends an empty body. * @return the result of the validation diff --git a/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java b/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java index d9431fc..ea0dcfa 100644 --- a/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java +++ b/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java @@ -22,4 +22,11 @@ public class SingleEmailBlock extends MailerLiteResponse { /** The etag of the email. Send it with the next write to the email. */ @SerializedName("etag") public String etag; + + /** + * The attributes that the API removed from the block, or null if there are none. Only createBlock and + * updateBlock fill it. getBlock and moveBlock leave it null. + */ + @SerializedName("rejected") + public EmailRejected rejected; } diff --git a/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java b/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java index ed78be7..fa45e58 100644 --- a/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java +++ b/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java @@ -275,6 +275,7 @@ public void getBlockDecodesTheBlock() throws Exception assertEquals("56", response.block.placement.after); assertNull(response.block.placement.before); assertNull(response.block.children); + assertNull(response.rejected); } @Test @@ -378,6 +379,24 @@ public void createBlockSendsTheBlock() throws Exception assertEquals("center", map(response.block.editorContent, "attrs").get("textAlign")); assertEquals("57", response.block.placement.after); assertNull(response.block.placement.before); + assertNull(response.rejected); + } + + @Test + public void createBlockReadsTheRejectedAttributes() throws Exception + { + client.respond(201, Fixtures.read("email_block_created_rejected.json")); + + Map content = paragraph("left", "Hi"); + map(content, "attrs").put("onclick", "x"); + + SingleEmailBlock response = emails.createBlock("123", "43", new EmailBlockInput(EmailBlockTypes.PARAGRAPH, content)); + + assertEquals(201, response.responseStatusCode); + assertEquals("44", response.etag); + assertEquals("59", response.block.id); + assertEquals("Some attributes were rejected.", response.rejected.message); + assertArrayEquals(new String[] {"editor_content.attrs.onclick"}, response.rejected.keys); } @Test @@ -471,6 +490,26 @@ public void updateBlockSendsTheEditorContent() throws Exception assertEquals("57", response.block.id); assertEquals("56", response.block.placement.after); assertEquals("58", response.block.placement.before); + assertNull(response.rejected); + } + + @Test + public void updateBlockReadsTheRejectedAttributes() throws Exception + { + client.respond(200, Fixtures.read("email_block_updated_rejected.json")); + + Map content = paragraph("left", "Hello again"); + map(content, "attrs").put("onclick", "y"); + content.put("mobile", Collections.singletonMap("onclick", "y")); + + SingleEmailBlock response = emails.updateBlock("123", "57", "44", content); + + assertEquals(200, response.responseStatusCode); + assertEquals("45", response.etag); + assertEquals("57", response.block.id); + assertEquals("Some attributes were rejected.", response.rejected.message); + assertArrayEquals(new String[] {"editor_content.attrs.onclick", "editor_content.mobile.onclick"}, + response.rejected.keys); } @Test @@ -554,6 +593,7 @@ public void moveBlockSendsThePlacement() throws Exception assertEquals("57", response.block.id); assertNull(response.block.placement.after); assertEquals("1", response.block.placement.before); + assertNull(response.rejected); } @Test @@ -611,6 +651,21 @@ public void validateBlockValid() throws Exception assertNull(response.rejected); } + @Test + public void validateBlockReadsTheRejectedAttributes() throws Exception + { + client.respond(200, Fixtures.read("email_block_validation_rejected.json")); + + Map content = paragraph("left", "Hi"); + map(content, "attrs").put("onclick", "x"); + + EmailValidation response = emails.validateBlock(new EmailBlockInput(EmailBlockTypes.PARAGRAPH, content)); + + assertTrue(response.valid); + assertEquals("Some attributes were rejected.", response.rejected.message); + assertArrayEquals(new String[] {"editor_content.attrs.onclick"}, response.rejected.keys); + } + @Test public void validateBlockInvalid() throws Exception { diff --git a/src/test/java/com/mailerlite/sdk/tests/ReadmeExamplesTest.java b/src/test/java/com/mailerlite/sdk/tests/ReadmeExamplesTest.java index af7bc44..cec55e2 100644 --- a/src/test/java/com/mailerlite/sdk/tests/ReadmeExamplesTest.java +++ b/src/test/java/com/mailerlite/sdk/tests/ReadmeExamplesTest.java @@ -113,13 +113,13 @@ private static List examples() list.add(new Example("Insert a block") .respond(200, Fixtures.read("email.json")) - .respond(201, Fixtures.read("email_block_created.json")) + .respond(201, Fixtures.read("email_block_created_rejected.json")) .expect("GET /emails/123456") .expect("POST /emails/123456/blocks")); list.add(new Example("Update a block") .respond(200, Fixtures.read("email_block.json")) - .respond(200, Fixtures.read("email_block_updated.json")) + .respond(200, Fixtures.read("email_block_updated_rejected.json")) .expect("GET /emails/123456/blocks/57") .expect("PATCH /emails/123456/blocks/57")); diff --git a/src/test/resources/responses/email_block_created_rejected.json b/src/test/resources/responses/email_block_created_rejected.json new file mode 100644 index 0000000..a2a7d5e --- /dev/null +++ b/src/test/resources/responses/email_block_created_rejected.json @@ -0,0 +1,15 @@ +{ + "data": { + "id": "59", + "type": "paragraph", + "editor_content": { + "content": [{"text": "Hi", "type": "text"}] + }, + "placement": {"after": "58", "before": null} + }, + "etag": "44", + "rejected": { + "message": "Some attributes were rejected.", + "keys": ["editor_content.attrs.onclick"] + } +} diff --git a/src/test/resources/responses/email_block_updated_rejected.json b/src/test/resources/responses/email_block_updated_rejected.json new file mode 100644 index 0000000..662d723 --- /dev/null +++ b/src/test/resources/responses/email_block_updated_rejected.json @@ -0,0 +1,16 @@ +{ + "data": { + "id": "57", + "type": "paragraph", + "editor_content": { + "attrs": {"textAlign": "left"}, + "content": [{"text": "Hello again", "type": "text"}] + }, + "placement": {"after": "56", "before": "58"} + }, + "etag": "45", + "rejected": { + "message": "Some attributes were rejected.", + "keys": ["editor_content.attrs.onclick", "editor_content.mobile.onclick"] + } +} diff --git a/src/test/resources/responses/email_block_validation_rejected.json b/src/test/resources/responses/email_block_validation_rejected.json new file mode 100644 index 0000000..5864af2 --- /dev/null +++ b/src/test/resources/responses/email_block_validation_rejected.json @@ -0,0 +1,9 @@ +{ + "valid": true, + "errors": {}, + "schema": {"version": "2.73.2", "hash": "0f3a9c"}, + "rejected": { + "message": "Some attributes were rejected.", + "keys": ["editor_content.attrs.onclick"] + } +} From 4d9bf141316f6d829f019d47f9234def563dfa29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Martty?= Date: Wed, 11 Nov 2026 16:34:29 +0100 Subject: [PATCH 2/2] docs: say that template_id also accepts the account's own templates The API now accepts as template_id a simple editor template from the shared gallery or a template that the account saved from its own email. The Javadoc of EmailBase.templateId and the README said "only a template from the shared gallery". The Javadoc of createTemplate and the README now say that the ID of the new template works as template_id. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +++- src/main/java/com/mailerlite/sdk/emails/EmailBase.java | 5 +++-- src/main/java/com/mailerlite/sdk/emails/Emails.java | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7648ff4..735978e 100644 --- a/README.md +++ b/README.md @@ -833,7 +833,7 @@ class Example { To build the email with the simple editor, set `editor` to `EmailEditors.SIMPLE`, and do not set `content`. Then change the email with [the email methods](#emails). The ID of the email is in `campaign.emails[0].id`. - `editor`: the only accepted value is `simple`, which selects the simple editor instead of the drag-and-drop builder. It has to be the same across every email in the payload; a mixed array is rejected. Setting it prohibits `emails.*.content`. -- `templateId` (`template_id`): the template the new email starts from. Allowed only when `editor` is `simple`, accepts only a template from the shared gallery, and also has to be the same across every email. +- `templateId` (`template_id`): the simple editor template the new email starts from. It is a template from the shared gallery, or a template that you saved from your own email with [`createTemplate`](#save-an-email-as-a-template). Allowed only when `editor` is `simple`, and also has to be the same across every email. - Only `create()` accepts `editor` and `templateId`. If an email has one of them set, `update()` gets a `422` error. - The SDK does not send `editor`, `templateId`, `replyTo` or `content` when they are `null`. @@ -1398,6 +1398,8 @@ class Example { Copies the email to a new template. The API cannot delete templates. +To start a new campaign email from the template, send the `id` of the template as `templateId` (`template_id`) when you [create a campaign with the simple editor](#create-a-campaign-with-the-simple-editor). + ```java // import .... diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailBase.java b/src/main/java/com/mailerlite/sdk/emails/EmailBase.java index 880d609..358cf56 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailBase.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailBase.java @@ -47,8 +47,9 @@ public class EmailBase extends ApiResource { public String editor; /** - * The template ID: the template the new email starts from. Allowed only when {@code editor} is {@code simple}, - * accepts only a template from the shared gallery, and also has to be the same across every email. + * The template ID: the simple editor template the new email starts from. It is a template from the shared + * gallery, or a template that you saved from your own email with {@code Emails.createTemplate()}. Allowed only + * when {@code editor} is {@code simple}, and also has to be the same across every email. *

* If it is null, the SDK does not send it. Only {@code CampaignBuilder.create()} accepts it. If it is set, * {@code CampaignBuilder.update()} gets a 422 error. diff --git a/src/main/java/com/mailerlite/sdk/emails/Emails.java b/src/main/java/com/mailerlite/sdk/emails/Emails.java index 33dd933..cc95a0d 100644 --- a/src/main/java/com/mailerlite/sdk/emails/Emails.java +++ b/src/main/java/com/mailerlite/sdk/emails/Emails.java @@ -367,6 +367,9 @@ public EmailValidation validateSettings(String emailId, EmailSettings settings) /** * Copies an email to a new template. The API cannot delete templates. + *

+ * To start a new campaign email from the template, set the templateId of the email to the ID of the template + * when you create a campaign with the simple editor. * * @param emailId the email ID * @param name the name of the new template @@ -380,6 +383,9 @@ public SingleEmailTemplate createTemplate(String emailId, String name) throws Ma /** * Copies an email to a new template. The API cannot delete templates. + *

+ * To start a new campaign email from the template, set the templateId of the email to the ID of the template + * when you create a campaign with the simple editor. * * @param emailId the email ID * @param name the name of the new template