Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parse.com cloud code GET function with parameters?

I'm writing a cloud code function in parse and I'm trying to figure out how to handle parameters in the GET url.

So I have a simple function like this:

Parse.Cloud.define("someFunction", function(request, response) {
    //  how can I use GET parameters here??

});

How to I rename the "someFunction" to handle GET parameters so I can use them in my cloud code function logic?

so for example I want to be able to pass in a name string: "myName" in the GET

https://api.parse.com/1/functions/someFunction?name=myName

Any simple example? I searched for a while I couldn't find one.

Thank you

EDIT: So I modified my function to look like this:

Parse.Cloud.define("someFunction", function(request, response) {
    //  how can I use GET parameters here??

    var name = request.params.name

    response.success("the name = " + name)
});

then I call it like this: https://api.parse.com/1/functions/someFunction?name=someName

what I get back is this:

{"result":"the name = **undefined**"}
like image 233
zumzum Avatar asked Sep 23 '26 01:09

zumzum


1 Answers

Cloud Functions are called with a POST request, not a GET request. Here is a simple example for cURL I took from the documentation [1].

curl -X POST \
  -H "X-Parse-Application-Id: YOUR_APP_ID" \
  -H "X-Parse-REST-API-Key: YOUR_REST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe"}' \
  https://api.parse.com/1/functions/someFunction

[1] https://www.parse.com/docs/cloud_code_guide#functions

like image 191
Björn Kaiser Avatar answered Sep 26 '26 09:09

Björn Kaiser