Home > Back-end >  Variable insertion in a json sent by curl to the Discord api. "unmatched close brace/bracket in
Variable insertion in a json sent by curl to the Discord api. "unmatched close brace/bracket in

Time:08-03

I have a small problem when sending a curl request to Discord.

my script :

#!/bin/bash
discord_webhook="https://discord.com/api/webhooks/ID/XXXXX"
tmp_file=/tmp/toblock.tmp
blocked_ip=$(paste -s -d ' ' $tmp_file)
if ! [ -z "$discord_webhook" ]; then
curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'$blocked_ip'"}]}' "$discord_webhook"
fi

content of /tmp/toblock.tmp is the two following lines (testing random ip) :

15.15.15.15
16.16.16.16

the error is

root@vm1 ~ # bash ad.sh
curl: (3) unmatched close brace/bracket in URL position 13:
16.16.16.16"}]}
            ^

Would someone see where the error is in my Curl request?

CodePudding user response:

$blocked_ip contains spaces, so that's splitting up the JSON into multiple arguments. You need to put it in double quotes to prevent this.

curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'"$blocked_ip"'"}]}' "$discord_webhook"
  • Related