Peter Jacobsen6906733
Posts: 0
Joined: Sun Jun 01, 2014 11:24 pm

I have been able to get my data from Xively using REST and am now having issues updating these same values

I need to have data formatted in the following way:
{
"version":"1.0.0",
"datastreams" : [ {
"id" : "example",
"current_value" : "333"
},
{
"id" : "key",
"current_value" : "value"
},
{
"id" : "datastream",
"current_value" : "1337"
}
]
}

I have created the request parameter "datastreams" with two sub-items named "id" and "current_value". I have mapped the running of the script to a button and in the mapping page added the following javascript to the "datastreams" idem:

var data_arr;
var datastreams=[];
datastreams.push({id:'Mode' , current_value:Appery('selectmenu1').val(datastream.current_value)});
datastreams.push({id:'Set_Temp' , current_value:Appery('mobileslider_6').val(datastream.current_value)});
datastreams.push({id:'mode_update' , current_value:'1'});
datastreams.push({id:'set_temp_update' , current_value:'1'});
data_arr.datastreams = datastreams;
return data_arr;

I getan error when testing that datastreams needs to be an array and that my request is the following:
{
"datastreams": {
"id": "",
"current_value": ""
}
}

Any ideas how to accomplish this upload?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

I have been able to get my data from Xively using REST and am now having issues updating these same values

Hi Peter.

It is looks like you have set "value" instead of get it from apperyio components.

Try following code instead of yours:

precode

var data_arr = {};
var datastreams = [];

datastreams.push({id: 'Mode', current_value: Appery('selectmenu1').val()});
datastreams.push({id: 'Set_Temp', current_value: Appery('mobileslider_6').val()});
datastreams.push({id: 'mode_update', current_value: '1'});
datastreams.push({id: 'set_temp_update', current_value: '1'});

data_arr.datastreams = datastreams;

//This will print currnt json string of "data_arr" into console. Please check console to see what is exactly in the "data_arr".
console.log("data_arr = " + JSON.stringify(data_arr) );

return data_arr;

/code/pre

Note: i've added to this code some debug message so please check out console to see what is exactly in the "data_arr".

Regards.

Peter Jacobsen6906733
Posts: 0
Joined: Sun Jun 01, 2014 11:24 pm

I have been able to get my data from Xively using REST and am now having issues updating these same values

I put this in and I am not sure where the console is. How do I open it?

This is the response if I hit test
{
"status":"400 Bad Request",
"url":"https://api.xively.com/v2/feeds/15485...",
"response":{
"title":"JSON Parser Error",
"errors":"\"datastreams\"" must be an array""
}
}"

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

I have been able to get my data from Xively using REST and am now having issues updating these same values

Peter,

Please open your APP in Chrome browser and press f12 on the keyboard.

After click on "console" tab. http://prntscr.com/3ov1c5/direct

Also i see you have parse error in your request. So this other issue.

Please give us your APP public link and describe steps how we can to reproduce this issue.

Regards.

Peter Jacobsen6906733
Posts: 0
Joined: Sun Jun 01, 2014 11:24 pm

I have been able to get my data from Xively using REST and am now having issues updating these same values

Yurii,

Here is the response:
data_arr = {"datastreams":[{"id":"Mode","current_value":"2"},{"id":"Set_Temp","current_value":"70"},{"id":"mode_update","current_value":"1"},{"id":"set_temp_update","current_value":"1"}]}

It looks good. Now how do I send this array to Xively? I have the service created but can't figure out where to bind this code....

Thank you.
Pete

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

I have been able to get my data from Xively using REST and am now having issues updating these same values

Hi Peter.

Please follow these steps:

1 Create new REST service with name "externalTest". http://prntscr.com/3p5zq9/direct

2 Fill URL field with url you need. And select other parameters like on the screen shot: http://prntscr.com/3p61w2/direct

3 Put button on the page and create click event handler for this button with following code:

precode

//Note you need to replace {"Hello": "world"} with data you need.
var yourDataToSend = {"Hello": "world"};

//Invoke service with your data.
externalRest.execute({method: "POST", contentType: "json", data: yourDataToSend });

/code/pre

Now when you start app and click on the button your service will invoked with data you passed inside "yourDataToSend" variable.

Note: in the service settings you should use Appery.io proxy cause of you send request to another domain.

Regards.

Return to “Issues”