How to call CURL command line in Jqeury?

Hi all,

I am trying to call the curl comand in Jquery on front end. similar like

# Using curl in your terminal
curl -u spark:spark \
     -d grant_type=password -d -d password=SuperSecret

But , i am not exactlly known how to make the code , below is what my tried:

		type:	"POST",
		url:	"",
		beforeSend: function(xhr) { 
	    	xhr.setRequestHeader("Authorization", "Basic " + btoa("spark:spark")); 
		data:	"grant_type=password&",
		dataType:	'json',
		success: function (data) {
	    error: function(){
	      alert("Cannot get data");

Is there anybody faced to this problem , or give me some sugguestion ?

The error message will be

Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR

Where are you sending the POST to? Are you still connected to the Spark Cloud, or are you hosting your own local cloud?

I’m using the following code: Perhaps you can use some of it.

var deviceID    = "<<insert device ID>>";	
var accessToken = "<<insert accesstoken>>";	
var baseURL = "";
var funcKey = "<<insert function name which you'd like to call>>"
var url = baseURL + deviceID + "/" + funcKey;

type: "POST",
url: url,
data: {
    access_token: accessToken,
	args: <<insert your data which you like to send>>
dataType: "json"
1 Like

Hi @Moors7 , thanks your reply,

what i used cloud url api will be successful access, the problem only happen on locally cloud call.

@kennethlimcp, what is my wrong for it , i guess, the locally cloud does not support spark cloud api ? if so , could give me some instructions for exactlly differences between locally and remote cloud ? I could nt find this in website.


You can see what’s available in the spark-server here: