I have a functioning shell script that looks something like this (works in Terminal):
curl -X POST --compressed -H "Content-Type:application/json" \
-H 'x-api-user: hdfjdfpjefpoj' \
-H 'x-api-key: fpjefpojwpfjmwefpj' \
https://example.com/api/v1/user/...
However, when I try to use this in an Applescript using do shell script, I get the error:
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
sh: line 1: -H: command not found
sh: line 2: -H: command not found
sh: line 3: https://example.com/api/v1/user/...: No such file or directory
Here's the Applescript:
do shell script "curl -X POST --compressed -H 'Content-Type:application/json'
-H 'x-api-user: hdfjdfpjefpoj'
-H 'x-api-key: fpjefpojwpfjmwefpj'
https://example.com/api/v1/user/..."
I've found some clues suggesting that do shell script doesn't behave exactly like Terminal, for security reasons. But I haven't found clues on how to work around this.
The same Applescript without the header info succeeds in passing the URL, but I need to send my credentials in the header.
I think it is because you have the command on multiple lines. Rather than one
The clue is sh: line 1: -H: command not found
This indicates that the shell is trying to find a command named -H but not finding it.
In most cases commands are always the first word in a command line string.
So this means the -H options are being interpreted as a command because they are the first word on a line. -H is clearly an option to curl and should follow it in the same line.
try it on a single line.
do shell script "curl -X POST --compressed -H 'Content-Type:application/json' -H 'x-api-user: hdfjdfpjefpoj' -H 'x-api-key: fpjefpojwpfjmwefpj' https://example.com/api/v1/user/..."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With