I made a Webhook Applet in IFTTT, which would send me a mail when "print" action triggers
In the URLs JSON body I can give values like this
curl -X POST -H "Content-Type: application/json" -d '{"value1":"9"}' https://maker.ifttt.com/trigger/print/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
What I want to do is find my public ip address and pass it as value1.
I found my IP by
value1=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo $value1
How can I pass value1 to above URL
I tried
'{"value1":"$value1"}'
'{"value1":{{$value1}}}'
'{"value1":{{value1}}}'
P.S: I have zero basic knowledge in shell script. This is the first time i'm doing it
Expressions inside single quotes do not get expanded in the shell, they are taken as literal. That means, if you store your IP address in a variable called ip
like this:
ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
and you put that in single quotes, it won't get expanded:
echo '$ip'
$ip
whereas if you put it in double quotes, it will get expanded:
echo "$ip"
192.80.136.233
So, you need double quotes, but that will cause a problem because you need double quotes around your JSON strings, so you need to escape those by prefixing them with backslashes. So, you want:
curl -X POST -H "Content-Type: application/json" -d "{\"value1\":\"$ip\"}"