Insert a variable into curl url

Hello,

I wnat insert the device id and token into $url, and I tried the follow code, but receive error :
“error”: “Not Found”, “device_name”: and the same error to access token.

What is wrong?

    $url = 'https://api.spark.io/v1/devices/'.$deviceID.'/led/?      
    access_token='.$accessToken;

This looks like PHP based on the syntax, so have you tried using the echo command to look at the result and the deviceID and accessToken variables?

Also you are doing a GET request for a Spark variable right? For a POST request you pass the access token as a parameter or use the bearer auth field.

1 Like

Yes, I can see the result using echo $deviceID and token. I need it to a POST.’

If I use this code works fine

$url = 'https://api.spark.io/v1/devices/238749874834/led/?access_token=423409283490283';

You need to do it this way (from the docs):

curl https://api.spark.io/v1/devices/0123456789abcdef/led \
  -d access_token=123412341234 \
  -d params=l1,HIGH

Notice how the access token is not part of the URL.