I'm trying to access the Spotify API using curl. I can do this in a one liner from the terminal and it works fine. For example:
curl -X GET "https://api.spotify.com/v1/tracks/2vEQ9zBiwbAVXzS2SOxodY" -H "Authorization: Bearer <mytoken>"
However, when I try to embed this in a bash script, I don't get any output. Here's my bash script:
#!/bin/sh
# For more info about endpoint references, visit:
# https://developer.spotify.com/web-api/endpoint-reference/
token=$(./spotifyAccess.php | jq '.access_token' | sed 's/\"//g') # where spotifyAccess.php genereates my access token
read -p "Please enter a method of authentification (e.g. GET, PUT, POST) " method
read -p "Please enter an endpoint (e.g. /v1/audio-features/{id}) " endpoint
read -p "Please enter a Spotify ID (e.g.2vEQ9zBiwbAVXzS2SOxodY) " id
url=$"https://api.spotify.com/$endpoint"
url=$(echo $url | sed "s/{id}/$id/g")
echo "My URl is: $url"
curl -X $method $url -H "Authorization: Bearer $token"
This is my first time using curl in a script, so maybe I'm doing something wrong? Right now, when I run the script, nothing happens.
EDIT:
Following @skr recommendation, I added the debug option set -x to my script. The output is as follow:
HTTP/1.1 404 Not Found
Server: nginx
Date: Tue, 08 Aug 2017 21:19:05 GMT
Content-Length: 0
Connection: keep-alive
Keep-Alive: timeout=600
Cache-Control: private, max-age=0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 604800
Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type