Create a dynamic list of dictionaries to send an order confirmation mail using Brevo API (no plugin)

Hi everyone,

I would need some help on the following:
General purpose: expose to Brevo API a list of ordered products (“ateliers” in following screenshots) on my website to be able to send an “order confirmation” email with all the products the user has bought (and metadata linked to each product such as “title”, “description”, …)

Challenge: I could not find a scalable methodology to transfer a variable nb of products list to Brevo API respecting its format guidelines

What I have done so far: I’m using the “trackEvent” endpoint, sending a Json with a “products” variable that host itself a list of dictionaries (Keyvalue pairs" defining each product). And on Brevo side, I’m using the “Reapeatable content” feature that detects the “products” variable and create a dynamic list of product with the right data to display.

That works well when I create an API call with a delimited list of products:
“eventdata”:{
“data”:{
“products”:[
{ “title”:“”,
“description”:“” },
{“title”:“”,
“description”:“”}
]
But I can’t find a way to create a dynamic list of dictionaries to pass to Brevo API in Bubble (that permits to pass a list of 1 product bought the same way as 5 products),

The closest way I reached is the following:
Creating a chain of “keyvaluepairs” hosted as URL parameter everytime the user add a product in his basket thanks to a Custom Event (see below where my product is named “ateliers”)

And pass it to a Repeating Group to create a list of “keyvalue” pairs:

And sending the following JSON

And, once populated with RG list, that results in the following:
“ateliers”:["{
titre:,
description:},
{…}
"]
which is not accepted by Brevo email template: I did not succeed in having the quote signs inside the curly braket (receiving an error from Bubble)

Hope I gave enough details. If not, feel free to ask for more.
Thank you very much in advance for any advice or idea you can have
Best,
Florent

You are not doing a dictionnaries but an array of object.

The correct way to do that is to use :format as text on the list of “ateliers”
This will look like Repeating group Ateliers’s list of text:format as text

Inside the format as text you will have

{
    "title": this item title:formatted as json-safe,
    "description": this item description:formatted as json-safe
}```

Delimiter ,

If you look, I didn't add ```"``` around description and title dynamic elemen because this will be added by :formatted as json-safe

Hi @Jici ,
Thank you for having looked into it.
If you look at my screenshot nb 1, you ll see that I’m already using “formatted as json-safe” transformer to build my “keyvalue” pair.
But the API connector refuses the format of the Json that s been created using that method. See the error message below

Let me know if that makes sense to you or if I’m missing something
Thank you again for the support

It’s hard to know without the end result of the JSON. What you can do, is to send the request to requestbin.com endpoint and validate your JSON

1 Like