RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

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!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Invoking an update service with Javascript

Hello Rakesh,

You use incorrect request (extra 'colName' parameter)

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

RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Invoking an update service with Javascript

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

RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

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); }
});

RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

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

RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

Is there a way to regenerate the service?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Invoking an update service with Javascript

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...

RakeshMalik
Posts: 0
Joined: Tue Dec 22, 2015 4:47 am

Invoking an update service with Javascript

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Invoking an update service with Javascript

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

Return to “Issues”