I’m trying to get the Mailgun api working, I can get it to send a plain text message with no issue but to dynamically add data to my mailgun templates I need to be able to send variables as in the X-Mailgun-Variables line below
Thanks @scott I looked at that page and it was helpful with laying out the bulk of the API, but there’s something specific in the fomratting of these variables that isn’t covered.
Adding as V:name Input Data, prefixed with an ‘&’ gets the variable recognised in Mailgun:
But the value seems a bit strange, I don;t see where the red text is coming from?..I’d like for some of these to be dynamic values from Wappler, but these return a blank in Mailgun if I put {{$POST_first_name}} for example?
The variable has been defined by he input data Name (which seems to work fine), and it’s value set by the Input Data Value (which is just some typed text:
this posts to Mailgun as
There’s only a single typed word word in the value. I’ve remade the API schema from scratch and typed the word in. I don’t see how that can trigger accidental characters. It must be something added by Wappler on making the API call? I’ve no doubt I’m doing something wrong somewhere but I can’t see the link between the entries in Wappler and the additional characters in the output…
the parameters from, to etc are set up as Query parameters in Wappler and work fine. I can send a plain text message through the api with no issue.
The user defined variables can be sent either in the X-Mailgun-Variables header, or prefixed with v: (which is what I’m doing here).
The user variables show here in the request:
is what’s posted from this in Wappler:
The input Name seems to work fine (the syntax sends a variable called name), but the value of name has the escaped characters added.
If I change the syntax (i.e. remove the &, or the =) the variable doesn’t get defined, because the post API request works there are no error messages to work from.
The variables link to mustaches in Mailgun templates, if they’re not present they’re just ignored and the message sends with the mustache label, rather than it’s value.
This is the response:
if I just type the parameter.
The variable doesn’t get passed in the request.
The syntax comes from using the same API in Bubble. I’ve only added in here after trial and error to try to get it to work. It gets me closer to it working than any other option I’ve tried!
From the initial query posted, using the JSON editor:
&v:name={{$_POST.first_name}}&
works fine. I get a variable passed and the text of the first name comes through.
so an ‘&’ symbol after each field prevents the escape characters being generated.
Expanding on that to pass the other parameters I need:
&v:name={{$_POST.first_name}}&v:body=I am the body&v:url=https://somewhere.com/"
&v:link={{token}}&
Which passes:
Posting in this format means I get escape characters in the url and (sometimes, depending on what characters it contains) in the hashed token.
I’ve tried enclosing in ’ ', " ", { }, {{ }}, ( ) all change the output (but add a variety of different characters) or, if I enclose both the parameter and the value, stop the post from passing the variables .
The outputs shown are what’s been passed, the screen shots are from the mailgun mail logs. So the escaping show in the emails as text, exactly as it’s shown in the user variables. If I take the extra ‘&’ out it adds escaping to the plain text entries too.
I know the structure isn’t correct, but it doesn’t work any other way!
After inspecting the Mailgun API - it turns out that Mailgun requires that you post all fields with the encoding multipart/form-data which is more common for upload files.