Question

All,

I am using Appcelerator Cloud Services as my backend for an AngularJS/Ionic Framework/PhoneGap mobile app I am working on. I am trying to query the ACS Posts object by user_id and tags_array.

My code is at the following gist : https://gist.github.com/bp4151/d6828f8d7af983316f99

I am formatting the query string as follows:

    getByFriends: function(user_ids, tag) {
        var query = "where={$and[{'user_id':$in['" + user_ids + "']},{'tags_array':$in['" + tag + "']}]}";

        return $http.get('https://api.cloud.appcelerator.com/v1/posts/query.json?key=' + globals.ACSKey + '&query=' + query + '&_session_id = ' + globals.session_id);

    },

I modified the code to the following, but I am still having no luck

getByFriends: function(user_ids, tag) {

        //return $http.get('https://api.cloud.appcelerator.com/v1/posts/query.json?key=' + globals.ACSKey + '&query=' + query + '&_session_id = ' + globals.session_id);
        return $http.get('https://api.cloud.appcelerator.com/v1/posts/query.json?key=' + globals.ACSKey + '&_session_id = ' + globals.session_id, {
            params: {
                query: "where={$and[{'user_id':$in['" + user_ids + "']},{'tags_array':$in['" + tag + "']}]}"
            }
        });
    },

I expect only one post record to be returned with the id I am passing in (532f233f1316e90b760eca00) but I am getting all posts back no matter what I try. If anyone can point my in the right direction, I would really appreciate it.

Thanks, Bruce

Was it helpful?

Solution

I figured it out. The issues are

  1. the params block is not set up properly,
  2. I need to decode the string that is being sent.
  3. I was confused by the documentation that stated query: where=... The correct way to do this with Angular is as I coded it below using "where":...

    get: function(user_id, tag) {

    console.log('PostService.get');
    
    return $http.get('https://api.cloud.appcelerator.com/v1/posts/query.json?key=' + 
        globals.ACSKey, 
        {
        params: {
            "where": decodeURIComponent('{"user_id": {"$in":["' + user_id + '"]},              
            "tags_array":"' + tag + '"}')
        }
    });
    

    },

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top