Postmark Batch API

I’m tryin to write my own Postmark API calls and I have some success doing so for the rather simple ones. The one I face issues with is the Send Emails in Batch API (i.e. Sending 500 emails at once). In the JSOn body, each individual email to be sent out is part of an array that consists of multiple parameters. The link to the API here . And the body looks like this for sending it to 2 email addresses:
How do I run through a list of email addresses and dynamically grow this JSON body to include each email address in each segment.

Hi, I don’t know if this is the best practice but here is how I did it.

I create a new thing called “Email list”. Add a text field to it, lets call it Json Body. Now create 1 Email list item in the database.

Then I create a new backend workflow to iterate through the list of objects that I want to pick the data from (An event’s guests, for example). In each iteration add the following workflow step:

Change a thing ----> Search for all Email Lists :first item
Add parameter to change: JSON Body
Value ----> JSON Body = Search for all Email Lists :first item’JSON Body:append {
Your JSON fields here

Let me explain how it works, So the field JSON body in Email List is like a notepad page for all your JSON text. What we are doing here is adding (appending to the text) the JSON objects one by one. At the end of the day we should have a text field with 500 JSON objects. Now you can pass this text field (JSON Body) in you API call to send the bulk email request :wink:

Tip: if you run into JSON parsing errors then make sure that you add commas , after each json object, except for the last one. You can do that by using conditionals to see if it’s the last item in your list and then add the text without comma.

If you do not know how to loop through a list in workflows, there are plenty of videos on youtube. Maybe start with this one How to Run a Loop in - YouTube ? :slight_smile:

You can do that now with :formatted as text from the list
So for example:
Do a search for user:formatted as text
First part will be (short version)

	"from": "your email",
	"to": "this user email",
	"Subject": "Test",
	"Textbody": "body"

and delimiter will be comma.

Shameless self-promotion - consider using my plugin and use bulk messages with templates. Postmark templates save a lot of hassle.

I created the plugin for my own purposes to stop all the painful JSON stuff and stop trying to create HTML email templates in Bubble. But just a suggestion, it is totally possible and quite a fun challenge to get it working pure Bubble :slight_smile: .


Just to add to this… I definitely recommend using :formatted as JSON-safe whilst building these out… it will escape any non-JSON safe characters inside your text… they always find their way into emails and they will prevent PostMark interpreting your call ← Lot’s of people get caught by this and it’s a really frustrating one to debug.

Note that using :formatted as JSON-safe will add enclosing " " either side of the expression, so you don’t need to. i.e. you should do something like this:

    "TextBody": body_input:formatted as JSON-safe

My personal choice is @lindsay_knowcode’s plugin though to avoid all of that :nerd_face:

1 Like

Thanks for this!! But just curious, I want to be able to dynamically set my Server API token as I would be using different Servers at different parts of my web app. Is this possible?

You can now optionally set the Server token in the Action and override the server token set at the plugin level.
I just added it to the plugin. Thanks, @manager that was a great suggestion. :slight_smile:

Screenshot 2022-08-12 at 07.22.32

1 Like