Mailgun template for batch sending with recipient variables in Handlebars expression - handlebars.js

I am trying to create a Mailgun template for batch sending, and the template needs to use a recipient variable within a Handlebars conditional to determine the language to use, like so:
<div>
{{#if %recipient.eng%}}
Hello
{{else}}
Bonjour
{{/if}}
</div>
However, when making a POST call to create the above template, I get the error response:
"message": "template parse error: Parse error on line 2:\nLexer error\nToken: Error{\"Unexpected character in expression: '%'\"}"
There isn't any documentation on the Mailgun site that uses batch sending with Handlebars, so it may not be possible.
Has anyone managed to successfully do this?

Having asked the question to Mailgun support, they recently got back to me.The conclusion is it is not possible to use recipient variables within handlebars expressions unfortunately.

You need to copy the participant variable to be a standard variable for the email. Note the line starting -F v:eng.
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <YOU#YOUR_DOMAIN_NAME>' \
-F to=alice#example.com \
-F to=bob#example.com \
-F recipient-variables='{"bob#example.com": {"first":"Bob", "id":1, "eng": true}, "alice#example.com": {"first":"Alice", "id": 2, "eng": false}}' \
-F v:eng='%recipient.eng%'
-F subject='Hey, %recipient.first%' \
-F text='If you wish to unsubscribe, click http://mailgun/unsubscribe/%recipient.id%'
You will then be able to access it using the standard variable in your handlebars template
<div>
{{#if %eng%}}
Hello
{{else}}
Bonjour
{{/if}}
</div>

Related

write all the curl arguments in a separate file to execute multipart/form-data request on webservices

I need to write all the curl arguments in a separate file(myconfig.txt) to be executed and output for each different lines of command in output.txt, output1.txt, output2.txt...so on.
The webservices should be requested with post (multipart/form-data) method.
I am trying this command curl -K myconfig.txt -o output.txt
contents of
myconfig.txt include URL="http://1x2.2x1.x6.1x2:3000/latto/get_notifications"<option="to";mobile="+91999xx6xx3x"> into the output.txt - 'Cannot get /latto/get_notifications'. It seems like web-services are being requested as get method. Please anyone tell me the syntax to write in myconfig file. So that I can get the right output in file.
However, When I run this command sudo curl --form option="to" --form mobile="+9199999yyyxx" 1x2.2x1.x6.1x2:3000/latto/get_notifications, output is successfully printed in terminal.
When I do a curl -k config.txt with config.txt containing this:
URL="http://my.test.domain/index.php"
-d option="to"
-d mobile="+91999xx6xx3x"
I get the result:
POST
array(2) {
["option"]=>
string(4) ""to""
["mobile"]=>
string(15) "" 91999xx6xx3x""
}
So I don't known what you mean with <option ...> but when you put it into your config file as stated above, it should work.
Btw. here is the php script that answered:
<?php
echo $_SERVER['REQUEST_METHOD']."\n";
var_dump($_REQUEST);
?>
This webservice accepts request in POST method and enctype multipart/form-data
URL="http://my.test.domain/get_notifications"
-F option=to
-F mobile=+91999xx6xx3x
After a lot of hit and trial, I got this working: curl -k config.txt with config.txt containing the above.

post data in meteorjs when using curl

I have the following method to post data to server :
curl --ipv4 http://localhost:3000/api/tests/1 -d #test.csv
I am trying to post a file with curl to a meter app
In meteor I am not able to read the data because I cant attach a key to the curl option data arrives as the key itself
example
contents of test.csv = > 1,1,1
at server
console.log('route to host' , this.request.body); yields {{1,1,1} : ''}
And yes I even tried -F data=#test.csv with no success as well
How can I add a key and make the contents of the file as value when posting through curl?
basically -d for curl means read the file and use its content as data
If you start the data with the letter #, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data #foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the # character to have a special interpretation use --data-raw instead.
in order to send the file itself youll need something like -F
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an # sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between # and < is then that # makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.
Example, to send your password file to the server, where 'password' is
the name of the form-field to which /etc/passwd will be the input:
curl -F password=#/etc/passwd www.mypasswords.com
in your case probably use -F
curl --ipv4 http://localhost:3000/api/tests/1 -F data=
if you want to file to be uploaded as a file use -F data=#test.csv
This works!!
curl --ipv4 --data-urlencode "csv#test.csv" http://localhost:3000/api/tests/1
Hope this helps someone :)

Uploading a file on a URL

Can anyone help me to find out a unix command that is used to upload/download a file on/from an URL?
Particular URL in which i'm trying to upload/download is protected with an user id and password.
I guess curl serves this purpose but not aware of how to use it? Could you please give me sugegstions on this?
curl has a command line argument named -d (for data) and you can use it like this to send a file(you need to add a # before a file-name to have curl treat it as a file and not a value:
curl -X POST -d #myfilename http://example.com/upload
You can add multiple -d arguments if you need to send a FORM value along with your file. Like so:
curl -X POST -d #myfilename -d name=MyFile http://example.com/upload

Gets "One or more of your tags are not allowed" when trying to create Open Graph action with friend tags

Fairly new to Open Graph. I am able to post an action with (using the sample code from when I created the action on the dev app page):
curl -F 'access_token=xxx' \
-F 'chatter=http://samples.ogp.me/225477284175782' \
-F 'place=134676523236535' \
'https://graph.facebook.com/me/[my_app]:[my_action]'
Everything looks fine on my timeline.. But when I tried to add "friend tags" using this:
curl -F 'access_token=xxx' \
-F 'chatter=http://samples.ogp.me/225477284175782' \
-F 'place=134676523236535' \
-F 'tags=854450021' \
'https://graph.facebook.com/me/[my_app]:[my_action]'
I got this error:
{"error":{"type":"Exception","message":"One or more of your tags are not allowed."}}
What am I missing? does the user being tagged have to auth the app or something?
Please help! Thanks.
Yeah, until the open graph is live (with Timeline) users can't be tagged unless they are an admin of the app. I think you also have to be friends with them too.

Post to Twitter using Terminal with CURL

I got this far:
:~ curl -u username:password -d status="new_status" http://twitter.com/statuses/update.xml
Now, how can I alias this with variables so I can easily twit from Terminal? How can I make the alias working through different sessions (when I close Terminal aliases reset).
Thanks!
Basic Authentication is no longer supported by twitter. Please use OAuth.
You clearly have the alias command: stick it in your ~/.bashrc and it will be set up when your bash shell starts. (.shrc should also work for sh-like shells.)
If you stick it in a script file as the previous answer suggests:
(a) add the line
#!/bin/sh
at the top;
(b) make sure it's on your path or you'll have to type the whole path to the script when you want to run it.
(c) to make it executable,
chmod +x tweet.sh
what about putting it a file and using argument 1 as $1:
# tweet.sh "post my status, moron!":
curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml
will that work?
You need to create a file in your home directory that will get referenced each time a new terminal opens.
Do a bit of research as to what to name the file, according to what type of shell you are using (tcsh looks for a file called .tcshrc while bash looks for .bashrc).
Once you have that file, make it executable by running:
chmod +x name_of_file
Then, in that file, create your alias (again, you'll need to research how to do this depending on what type of shell you are using). For tcsh, my alias looks like this:
alias tw 'curl -u username:password -d status=\!^ http://twitter.com/statuses/update.xml'
Bash aliases use an equals sign. A bash alias would look something more like this:
alias tw='curl -u username:password -d status=\!^ http://twitter.com/statuses/update.xml'
Note the change in the command after "status=". The \!^ tells the line of code to insert the first argument passed after the alias itself.
Save your file.
You could then run an update to twitter by typing the following in a new terminal:
tw 'my first post to twitter via the terminal, using aliases'
Don't forget to escape 'special' characters (like exclamations) with the escape character, \ (i.e. \!)
Since Basic Authentication is no longer supported by twitter, you have to use OAuth to achieve your goal.
But if you just want to post to Twitter using terminal, there are many application can do it.
Take a look at Rainbowstream or t
With rainbowstream, the following lines will let you tweet from console:
$ sudo pip install rainbowstream
$ rainbowstream
[#yourscreenname]t whatever you want

Resources