GET command error in PuTTY

I tried to connect using the PuTTY command line to access the spark.variable in FW. But having following error.

GET https://api.spark.io/v1/devices/53…87/systemState?access_token=09…1b

Once I press enter, following error return

301 Moved Permanently

Anyone has idea what I had done wrong this time with API calls :frowning:

Try without the \ after systemState so

 https://api.spark.io/v1/devices/53....87systemState?access_token=xxx

Unfortunately, this does not work either. Since I had this working in HTML, so I open the Chrome “Inspect Element” to view the Request Header. it is same as I type in. I even cut and paste everything Chrome has send out but return same error number.

So this must be the PuTTY setting. I am using following

  • Port = 80
  • Connection type : Telnet
  • negotiation mode : Passive
  • keyboard sends Telnet special commands : off
  • Return key sends new line : on

OK so you are trying to use telnet over PuTTY as a web browser? The Spark API is always HTTPS so I think the moved permanently refers to moving to HTTPS.

You need to change to port 443 and use SSL. Plus the GET request does not always include the host name and requires a version tag, and you likely need a separate host: line.

GET v1/devices/53…87/systemState?access_token=09…1b HTTP/1.1
Host: api.spark.io
<>

Why not use curl instead?

Now, I just download the curl and use the command data as in Spark doc. It is working.

However, I still don’t know what had I done wrong in PuTTY in term of configuration.
Or may be PuTTY does not support SSL ??
I am using this for getting UART debug for the core and it is easy to use.

Thanks again.

HI @Dilbert

PuTTY does support SSL, but the format of a HTTP or HTTPS request is not just one line but many lines typically. HTTPS with SSL runs on port 443 not port 80 like you where using. You can see this by passing the -v flag to your curl request to see all the things it is doing.

So while it is possible to use PuTTY to do HTTPS requests, curl is a whole lot easier.

These command format is killing me again :frowning: Spend an hour and still not able to get “digitalread” function to work

curl https://api.spark.io/v1/devices/0123456789abcdef01234567/brew \
     -d access_token=1234123412341234123412341234123412341234 \
     -d "args=202,230"

curl “https://api.spark.io/v1/devices/0123456789abcdef01234567/brew ?access_token=1234123412341234123412341234123412341234\args=D0”

I do get the Spark.variable to work though. I tried to create the .bat file in DOS. It had been a long time last edit batch.
Tried using the ^ to wrap the line but did not work.

Just to do everything is single line and not working neither.

Hi @Dilbert

So “brew” is a sample function name in the docs, for Tinker the function names are digitalread, digitalwrite, analogread, analogwrite. These always take a string and a return an int and go at the end of the API URL.

Curl automatically does a POST request if you pass args with the -d flag so that works great for Spark functions but not for Spark variables where you want a GET request.

Yes, I did not use “brew” for test. I just use this as example for questions.

Finally, I discover the mistakes.

  1. I could not use the " " if I want to wrap around the long line
  2. I have to use the ^ in command batch file instead
  3. need to pay attention to missing “space”, I missed a space in between

curl https://api.spark.io/v1/devices/0123456789abcdef01234567/digitalread ^
-d access_token=1234123412341234123412341234123412341234 ^
-d “args=D0”

Thanks for all the hints and suggestions. Now I can move on again :smiley:
It over 10 years since I last edit a batch file in project … Sound like an “old man” :wink:

2 Likes

Hi @Dilbert

You can always use the spark-cli as well! https://github.com/spark/spark-cli :slight_smile:

Thanks,
David