2

I need to retrieve a specific data using AngularJS's $http calling Parse RESTFUL API, the only way Parse allows me to do it is to send in a "--data-urlencode where={"storeId":2}" into a curl call.

curl -X GET -H "X-Parse-Application-Id:ApplicationId" -H "X-Parse-REST-API-Key: ApiKey" -G --data-urlencode 'where={"storeId":2}' https://api.parse.com/1/classes/Stores/

see here: https://parse.com/docs/rest#queries-arrays

I'm able to return a JSON result using the terminal but not with $http(). Anyone know how i can inject "--data-urlencode where={"storeId":2}" into the AngularJS $http() or $resource() methods?

see here: http://docs.angularjs.org/api/ng.$http

1 Answer 1

5

Looking a the python reference of the parse api, I guess the where={"storeId":2} can be appended as a query parameter (I cannot test this without access to the parse api). From the reference:

params = urllib.urlencode({"where":json.dumps({
   "arrayKey": 2
})})

In AngularJS you can add query parameters with the param key in $http's config object:

var req = $http({
    params: {
        where: {storeId: 2},
    },
    headers: {
        'X-Parse-Application-Id': 'ApplicationID',
        'X-Parse-REST-API-Key': 'ApiKey'
    }
    //... other params, like URL
});

The params.where value will be turned into a JSON string automatically. I am not sure if the query parameters get URL encoded by default, if not, JSON encode them manually and apply the encodeURIComponent function.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.