Page 1 of 2

Invoking an update service with Javascript

Posted: Mon May 23, 2016 8:53 pm
by RakeshMalik

I'm trying to call an update service to add a value to an existing DB entry. I have the ID, and I generated an update service, and imported it into the pages data services. I'm trying to call it this code:
updateHuntQuestions.execute({
data: {
'_id' : huntId,
'colName': {
'Questions':questions
}
},
success : function(){ console.log('added questions');},
error: function(){ console.log('error adding questions');}
});

And I'm getting this:https://api.appery.io/rest/1/db/colle...
with a bad request. I verified that the huntId variable is being set correctly, so clearly I'm doing something wrong in invoking the service, but I'm not sure what it is that I'm doing wrong. The other parameter is an array of strings, and as far as I can tell is also being set correctly.

Thanks!


Invoking an update service with Javascript

Posted: Tue May 24, 2016 7:52 am
by Serhii Kulibaba

Hello Rakesh,

You use incorrect request (extra 'colName' parameter)

Please look at this topic with a correct request: https://getsatisfaction.com/apperyio/...


Invoking an update service with Javascript

Posted: Sat Jun 18, 2016 6:14 am
by RakeshMalik

I updated my code using what's listed in that topic, but it's not working. I'm getting a success result, but the update isn't happening.

Code: Select all

 updateHuntQuestions.execute({ 
     body: { 
         where : {'_id' : huntId}, 
         operations : {$set: {'Questions': questions} } 
     }, 
     success : function(){console.log('hunt updated successfully');}, 
     error : function(err){console.log('error: ' + err); } 
 }); 

The ID is correct, and the parameter is an array of strings as expected, but the update is leaving the field blank.


Invoking an update service with Javascript

Posted: Tue Jun 21, 2016 6:13 am
by Serhii Kulibaba

What fileld is empty after updating? Is it Questions column?
Please show request parameters from the network tab: https://developer.chrome.com/devtools...


Invoking an update service with Javascript

Posted: Wed Jun 22, 2016 1:19 am
by RakeshMalik

It turns out that the rest app wasn't refreshing with updated code, so it was hiding a problem.

So this code:
updateHuntQuestions.execute({
body: {
where : {'id' : huntId.id},
operations : {$set: {'Questions': questions} }
},
success : function(){console.log('hunt updated successfully');},
error : function(err){console.log('error: '); console.log(err); }
});

Gives me this error:
Object {readyState: 4, responseText: "{"code":"DBSU210","description":"Invalid object ID: '{_id}'"}", responseJSON: Object, status: 400, statusText: "Bad Request"}

I've tried it with _id in quotes as well as without quotes, and I'm getting the same result.

I'm also getting the same error when I use the hunt name instead of ID:
updateHuntQuestions.execute({
body: {
where : {'Name' : huntId},
operations : {$set: {'Questions': questions} }
},
success : function(){console.log('hunt updated successfully');},
error : function(err){console.log('error: '); console.log(err); }
});


Invoking an update service with Javascript

Posted: Wed Jun 22, 2016 2:33 am
by RakeshMalik

I tried saving the huntId and Questions array in local storage, and setting up the mapping using the app builder. The results are different, thought not any better.

jquery-2.1.1.js:8623 OPTIONS ]https://api.appery.io/rest/1/db/colle... send @ jquery-2.1.1.js:8623jQuery.extend.ajax @ jquery-2.1.1.js:8152Apperyio.RestService.$a.createClass.process @ appery.js:476Apperyio.DataSource.$a.createClass.execute @ appery.js:296addQuestionsToHunt @ VM29027:688createHunt.execute.success @ VM29027:714fire @ jquery-2.1.1.js:3073self.fireWith @ jquery-2.1.1.js:3185done @ jquery-2.1.1.js:8251(anonymous function) @ jquery-2.1.1.js:8598
HuntBuilder.html:1 XMLHttpRequest cannot load ]https://api.appery.io/rest/1/db/colle.... Response for preflight has invalid HTTP status code 400

Request URL:]https://api.appery.io/rest/1/db/colle...
Request Method:OPTIONS
Status Code:400 Bad Request
Remote Address:54.221.205.233:443


Invoking an update service with Javascript

Posted: Wed Jun 22, 2016 2:50 am
by RakeshMalik

Is there a way to regenerate the service?


Invoking an update service with Javascript

Posted: Wed Jun 22, 2016 6:41 am
by Serhii Kulibaba

Do you want to update only one database item? If so - you are able to import that database service.
Else, if you want to update multiple database items, please use request below for that: https://devcenter.appery.io/documenta...


Invoking an update service with Javascript

Posted: Fri Jun 24, 2016 2:21 am
by RakeshMalik

Just one, and I already have a database service imported that isn't working. It's having trouble with the mapping:

mapping-impl.js:258 Uncaught TypeError: Apperyio.storage[name].get is not a function

So clearly something is wrong in the imported service.

Once again, is there a way to regenerate the service?


Invoking an update service with Javascript

Posted: Mon Jun 27, 2016 6:40 pm
by Serhii Kulibaba

Please provide us with a public app link (https://devcenter.appery.io/documenta...) and exact steps to reproduce this problem.