0

Im trying to get a coding project where you input the auth and endpoint into a program, which would run a webhook, in otherwords an ui that uses zoom's incoming webhook api to send things in private zoom channels

The goal here was to run something, but I ended up changing it to echoing it for testing purpouses. It matched up with the example curl that was given when using incoming webhooks example curl. For some reason when I remove the echo, its giving me an error:

 URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: [authkey]'

Not sure whats wrong. any ideas?

echo "enter endpoint"
read endpoint
echo "enter auth"
read auth
while 
    true
    do
    echo curl \'${endpoint}\' '-X POST -H' \''Authorization:' ${auth}\' -d \''Hello World!'\'
 done

shellter
  • 36,525
  • 7
  • 83
  • 90
  • For most cases, using dbl-quotes around `"${envVars}"` is the safe bet.. Good luck. – shellter Mar 20 '23 at 21:48
  • `"$endpoint"`, not `\'$endpoint\'`. `-X POST`, not `'-X POST'`. – Charles Duffy Mar 20 '23 at 22:02
  • You're using literal quotes (quotes that are part of your data) where you should only have syntactic quotes (quotes that are shell syntax). This is a common mistake made by people who try to use `echo` to debug shell command lines; it's **completely** unsuited to that purpose, because its output is wildly misleading: you can't tell the difference between `echo "commandname" "first argument" "second argument"` and `echo "commandname first" "argument second" argument`, even though they're completely different commands. – Charles Duffy Mar 20 '23 at 22:02
  • The inverse of the problem you asked here is [bash inserting quotes into string before execution](https://stackoverflow.com/questions/6087494/bash-inserting-quotes-into-string-before-execution) -- it's a different mistake, but it's based on the exact same misconception. – Charles Duffy Mar 20 '23 at 22:08

2 Answers2

0
curl 'url' -X POST -H 'Authorization: token' -d 'Hello World!' 

works for me. The quotation marks on -X POST -H are incorrect.

shellter
  • 36,525
  • 7
  • 83
  • 90
0

Don't try to quote to make echo emit the same thing as set -x output for your correct command. Instead, quote to make running the script with set -x emit the same thing as set -x output for your correct command.

curl "${endpoint}" -X POST -H "Authorization: ${auth}" -d 'Hello World!'

echo emits only literal data, but a shell command contains shell syntax that is not literal data, but instead are instructions to the shell on how to parse the rest of the command. You need that syntax to be correct, and also to be understood by the shell as syntax; when you add escaping to make echo write that content as output, you're changing it from syntax to data, so it no longer serves its original purpose.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Got it. Im sorry, im new to bash, and am trying to figure out a better way to trouble shoot – popichu Mar 21 '23 at 02:17
  • Also is there a way to fix that? – popichu Mar 21 '23 at 02:24
  • Not sure what you mean by "fix that". In terms of how to replace troubleshooting with `echo` -- use `set -x` to tell the shell to do trace logging (and `set +x` to turn it back off); compare the `set -x` outputs of your real/working manual command and of your script and that if nothing else usually makes it much easier to ask a good SO question, but is often enough to let you solve the problem on your own. – Charles Duffy Mar 22 '23 at 17:09