Tinker API returning "-1" (failing) but I don't know why

I have been trying to send an API request to my Spark Core to no avail.

They URL:
https://api.spark.io/v1/devices/1234512345/digitalwrite?access_token=1234512345

in the header, I have set a “params” variable to “D0,HIGH” and have tried attaching the params variable to the end of the URL as well, but the cloud service always returns:

{
“id”: “1234512345”,
“name”: “core-name”,
“last_app”: null,
“connected”: true,
“return_value”: -1
}

Why is the return_value -1? I know that means it failed, but I have no idea why

Update: I was able to toggle the D0 pin with curl, but cannot get it working in any other http library. I must be misunderstanding what the -d parameter means in curl. Any ideas?

Hi @marksbren What method are you using to create the POST request? If with code, can you share the code so we can take a look?

I like to use the Advanced Rest Client extension for Chrome to test things out… here’s how you would use it to generate a POST request for digitalWrite() with the Tinker API/Application.

Setup:

The Response:

There are many ways to Setup the request, you can form xml encode or send as JSON, put the parameters in one long string like I did, or click the Form button and under each Key/Value pair in nice little boxes.

When you need to use GET requests it’s easy to change the setup as well. Not to mention you can save your requests and reuse them later if you don’t want to have to keep typing your ID and access token in.

When you use the -d parameter in curl it automatically creates a POST request, and if you use curl like https://api.spark.io/v1/devices/1234512345/digitalwrite?access_token=1234512345&params=D7,HIGH it creates a GET request which won’t work when calling Spark.function()'s such as the ones used in the Tinker API. Hope that helps!

1 Like