3

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**"}
Community
  • 1
  • 1
zumzum
  • 17,984
  • 26
  • 111
  • 172

2 Answers2

6

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

Björn Kaiser
  • 9,882
  • 4
  • 37
  • 57
0

try calling the Cloud from JS layer...

Parse.initialize(appId, jsId);

p =  Parse.Cloud.run('someFunc', {"name":refToName}).then(function(result) {
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43