Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

how to update an existing json object(Apigee Baas Response) in titanium studio

$
0
0

hi, i am builting an android app in titanium studio with Rest api (Apigee Baas) as backend. i have some data in the Apigee Baas, for example name, address, mobile etc, now i want to update these values from my android mobile app. First in my code,i get the response from Rest API in the following manner..

{ "action" : "get",

"application" : "b97c5330-c25c-11e4-b2dd-a178ffc5bddb",

"params" : { "ql" : [ "select * where username='prii'" ] },

"path" : "/attendances",

"uri" : "https://api.usergrid.com/pri_95616/login/attendances",

"entities" : [ { "uuid" : "9d465d4a-c721-11e4-8dae-eb9b9c1ec583",

"type" : "attendance",

"created" : 1425990791444,

"modified" : 1425990791444,

"attendance" : "0",

"metadata" : { "path" : "/attendances/9d465d4a-c721-11e4-8dae-eb9b9c1ec583" }

}

now i am getting the attendance value in my code and incrementing its value and trying to update the new value to my existing to Rest API(Apigee Baas).

I have tried the following code, and in titanium studio and can any one please help me.

index.js file

function doClick(e) {

var url = "api.usergrid.com/PRI_95616/LOGIN/attendances?ql=select * where username='"+prii+"'";

var client = Ti.Network.createHTTPClient({

onload : function(e) {

var params={};

var json=JSON.parse(this.responseText);

user=json.entities[0].username;

params["username"]=user;

attn=json.entities[0].attendance;

params["attendance"]=attn;

var window = Alloy.createController('newwin', params).getView();

window.open();

}

client.open("GET", url);

client.send();

}

in the above code i am retreiving the values from the json response and want to update the value of attendance value and return it back to the same json entity.

following code i have tried to update and send back to Rest Api.

newwin.js file

var args = arguments[0] || {};

$.atn.text=args.attendance;

var abc;

abc=parseInt($.atn.text);

var url="api.usergrid.com/PRI_95616/LOGIN/attendances?";

var obj = { "username":" "+args.username+" ",

"attendance" : " "+ abc +" " };

var client = Ti.Network.createHTTPClient({

onload : function(e) { }

onerror : function(e) { }

client.setRequestHeader('content-type', 'JSON');

client.open("PUT", url);

client.send(JSON.stringify(obj));

now when i am executing this code a new entity is getting created in the Rest APi and the existing entity is not getting updated. so can any one help me on these.


Viewing all articles
Browse latest Browse all 8068

Trending Articles