RESTful service GUI alternative to Curl

Hi,

Has anyone had any luck using a GUI tool rather than curl?
I’ve tried https://code.google.com/p/cocoa-rest-client/ and also two Chrome apps, but I get ‘permission denied’ errors when I’m sending the correct access_token value.
It would be good to use a GUI as they allow you to save URLs and hence test lots of functions very quickly.

Will.

I’ve heard good things about Postman: http://www.getpostman.com/

Also, this is a great tool that someone in the community created, specifically for Spark: http://jflasher.github.io/spark-helper/

1 Like

I agree on Postman - I use it all of the time to test out REST and SOAP interfaces. It allows you to save collections of requests and keeps a history.

That spark-helper works great! But postman give me a 403 Error with permission denied.

You can use APIGEE. Its a great way to test REST services on UI.

Did you have the correct access token? A 403 error would happen if you don’t have permission to control that Core.

What about a {
“code”: 400,
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}
I have copied and pasted the access token from the wed ide.

Hey @dcrand,

It sounds like maybe the access token needs to be in a different spot, or is missing from the request, or maybe the parameter name is mistyped. For the PUT/POST requests, the access_token needs to be a body parameter, and for the GET requests it should be in the url.

Thanks!
David

I’m a complete noob don’t know what I’m missing. I’m using “Controlling LEDs over the Internet” example from the spark documents and putting my id and token numbers in the api example. I’m using postman to send the api request as I’m on a windows machine. The code seem to flash ok on the core.

Have you tried using the Spark API Helper? Might work better than postman. http://jflasher.github.io/spark-helper

@zach I tried the Spark API Helper it flashed success however the led did not turn on. I;ve doubled checked that the id and token are in the right place. I used “led”, ledControl for the function entry and l2,HIGH for the data entry. Appears I have a large learning curve with this core.

Can you share your code and what you see on the API helper (maybe a screenshot)? Happy to help you through it.

int led1 = D0;
int led2 = D1;

// Function prototypes
int ledControl(String command);

// This routine runs only once upon reset
void setup()
{
//Register our Spark function here
Spark.function(“led”, ledControl);

// Configure the pins to be outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);

// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}

// This routine loops forever
void loop()
{
// Nothing to do here
}

// This function gets called whenever there is a matching API request
// the command string format is l,
// for example: l1,HIGH or l1,LOW
// l2,HIGH or l2,LOW

int ledControl(String command)
{
int state = 0;
//find out the pin number and convert the ascii to integer
int pinNumber = command.charAt(1) - ‘0’;
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 1) return -1;

// find out the state of the led
if(command.substring(3,7) == “HIGH”) state = 1;
else if(command.substring(3,6) == “LOW”) state = 0;
else return -1;

// write to the appropriate pin
digitalWrite(pinNumber, state);
return 1;
}

Hey @dcrand,

I tried your code and example, and I think I spotted the problem!

I think your function name should read:

led

I think your request data should read:

l0, HIGH

or

l1,HIGH

Since the code you posted only writes to one of two pins, and it appears to be ‘0’ based.

Thanks!
David

@Dave Thanks a lot that worked just fine. Now I have to learn to more about function names and data.
Is there way that you can see the full post url that API Helper is sending I would like to learn more about post and get using that format?
Thanks again

sure thing! If you’re using that particular API helper page, you can open up chrome developer tools and view the network tab. Most browsers have a developer tools window that will show you what’s being sent, or you could use a tool like Fiddler, Charles, or Wireshark to watch the requests directly. :slight_smile:

But it’s HTTPS - you’re not going to see the requests are you?

It work 3 times then hasn’t worked since and the development tools showed https://api.spark.io/v1/devices/deviceid/led POST
200
OK
application/json
jquery-2.0.3.js:7845
Script
389 B
125 B
156 ms
153 ms
153 ms3 ms

so don’t know what it shows when it’s working.

Sorry, you’re probably right @wdj, I think I have fiddler and stuff setup on my box to show everything while I’m debugging, so your results may vary.

I’ve posted my Postman collection at https://www.getpostman.com/collections/80e0186c26d47b54fc93. Choose “Import from URL” and Postman should slurp it right up. You also need to set up a Postman environment with two variables for the above collection to work:

DEVICE_ID
ACCESS_TOKEN

I was not able to get the “Verifing and Flashing new firmware” to work.

I also put in the “Tinker” calls, but that of course requires that you have the Tinker sketch loaded on the Core.

If someone figures out the Flashing of firmware in Postman, please post back.

Dave O

1 Like