I have a flag in the _user collection. I want to be able to set this flag in all records of the _user collection. How can I update the entire collection?
I have a flag in the _user collection. I want to be able to set this flag in all records of the _user collection. How can I update the entire collection?
I have created a service to list all users and the output is save into an array of users.
I have a 'users' variable saved in session storage, a 'User' Model, which contains all the fields of the _user collection. I have a 'Users' model which is an array of the User Model. The service works correctly and the user variable is loaded. A sample users session variable is as follows:
[{"userId":"55758504e4b0b40eb7813c50","username":"terry","email":"a href="mailto:terry@mrtaxsoftware.com" rel="nofollow"terry@mrtaxsoftware.com/a","firstName":"Terry","lastName":"Gilliver","address":"56 Stowe Close","county":"Leicestershire","town":"Ashby-de-la-Zouch","postcode":"LE65 2NY","telephone":"07925273831","newsAvailable":false,"eventsAvailable":false},{"userId":"5579d8fde4b0b40eb781f335","username":"admin","email":"a href="mailto:terry@mrtaxsoftware.com" rel="nofollow"terry@mrtaxsoftware.com/a","firstName":"Terry","lastName":"Gilliver","address":"56 Stowe Close","county":"Leicestershire","town":"Ashby","postcode":"LE65 2NY","telephone":"07925273831","newsAvailable":false,"eventsAvailable":false}]
I I need to loop through each userId in this array to execute an update service. I am unsure how to get the userId from each array element.
Can you suggest how to do this?
Ok, I figured it out:
code
/* loop through users */
var users = Apperyio.storage.users.get();
var arrayLength = users.length
for (i = 0; i < arrayLength; i++) {
console.log(users.userId);
}/code
Proceeding a bit further now, I want to run the update service for the users collection.
My code now reads:
code/* loop through users */
var users = Apperyio.storage.users.get();
var arrayLength = users.length;
for (i = 0; i < arrayLength; i++) {
console.log(users.userId);
updateUsers.execute({body : {where : {user_id : users.userId}, operations : {$set : {events_available : true} } } });
}/code
The update fails and the console log entry is:
PUT https://api.appery.io/rest/1/db/users/ 405 (Method Not Allowed)
My update service works if you map the data via the graphical interface, so it must be a syntactical error in my call to the service.
The service is defined as :
Can you advise where my error is?
Is there any documentation which fully describes the javascript syntax of a service.execute({}) statement? It seems to be a bit sparse.
Hi Terry -
Let's start from the error that you are getting, could you please check the network tab in the browser console -- what are you getting there as a response from your service call?
Try to pass headers parameters within execution of your service this way: https://devcenter.appery.io/documenta...
And in network tab you should be able to see what parameters you are sending with your service invocation.
I too am getting this error when trying to build a service on the users collection:
{
"status":400,
"uri":"https://api.appery.io/rest/1/db/users/",
"response":{
"code":"DBUQ002",
"description":"database id not specified"
}
}
I am using a REST Service, and in the Header request parameter I have
X-Appery-Database-Id. I have tried using {database_id} and the actual ID, no luck. I cannot get this to work in test.
I followed instructions from Yurii:
https://getsatisfaction.com/apperyio/...
DB is shared with support already.
Jack,
Could you please specify the name of this db?