I am trying to include this curl command (to the Dropbox audit api) in a bash script:
curl -X POST https://api.dropboxapi.com/2/team_log/get_events --header 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXX' --header 'Content-Type: application/json' --data '{"time":{"start_time":"2018-07-16T18:07:56Z"}}'
I have replaced the auth token with XXXXX etc.
In my script the timestamp is actually a variable called $LAST.
I build up the curl command like this:
LAST=$(date +"%Y-%m-%dT%H:%m:%SZ")
DROPBOX1=$(echo 'curl -X POST https://api.dropboxapi.com/2/team_log/get_events --header '\''Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXX'\'' --header '\''Content-Type: application/json'\'' --data '\''{"time":{"start_time":"')
DROPBOX2=$(echo '"}}'\''')
CURLSTRING=$DROPBOX1$LAST$DROPBOX2
echo $CURLSTRING
$CURLSTRING
I build it up this way otherwise $LAST was problematic due to all the single and double quotes in the curl POST.
Running that small script gives this output:
curl -X POST https://api.dropboxapi.com/2/team_log/get_events --header 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX' --header 'Content-Type: application/json' --data '{"time":{"start_time":"2018-07-16T18:07:56Z"}}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 175 0 127 100 48 232 87 --:--:-- --:--:-- --:--:-- 231
curl: (6) Could not resolve host: Bearer
curl: (6) Could not resolve host: XXXXXXXXXXXXXXXXXXXXXXXXX'
curl: (6) Could not resolve host: application
As can been seen the echo command in the script shows what looks to be a completely valid curl command - indeed if I cut and past that output to the command line, it works. However, as the rest of the output shows in the bash script itself the curl command is not being interpreted properly.
I cannot for the life of me figure out why this is. Clearly echo is preserving the string correctly, whereas the curl command is breaking up the $CURLSTRING somehow. I am obviously not correctly using some combination of single and double quotes, but quite where is breaking is unclear.
thanks
Rob