0

I'm currently trying to use an API and for the API, the developer console of that app asks the developer to submit a callback URL. Whenever the user of the app does something, it submits a GET request to the callback URL and I can retrieve data from that request. The current url I am using is https://appId:javascript-key=myJavascriptKey@api.parse.com/1/functions/receiveInfo. How can I handle the data, a.k.a the GET parameters, from the GET request? I found an answer on Parse.com that says how to retrieve data from a POST request, but all it says is that data = request.body. Do I do the same for GET requests and if so what do I do after that? Is request.body a json value?

Parse.Cloud.define("receiveInfo", function(request,response){

        var params = request.body;//is this right to get the GET parameters they send? if so what do I do next?

    });
shreyashirday
  • 892
  • 1
  • 10
  • 34
  • Can you be a little clearer? It seems like you are trying to use the REST API to call a cloud function. It will be much easier to answer if you post the code you are working with. – sarvesh Oct 30 '14 at 03:24
  • http://docs.justyo.co/v1.0/docs/receiving-a-yo-with-the-api--please read the first paragraph. Essentially, I am just trying to handle the GET parameters they give using cloud code. The function is empty but it is called "retrieveInfo". I'm not sure what to do in the function. – shreyashirday Oct 30 '14 at 04:30
  • You don't do a GET call to your cloud function, you need to do a POST like explained here (https://www.parse.com/docs/cloud_code_guide#functions-calling) in the documentation. You should be able to retrieve the values you pass by request.params. – sarvesh Oct 30 '14 at 04:47
  • I'm not making the call, the app is. Did you read the first paragraph? – shreyashirday Oct 30 '14 at 22:11
  • What is "that app" you are referring to? – sarvesh Oct 31 '14 at 00:47
  • "Yo" is the name of the app – shreyashirday Oct 31 '14 at 16:46

1 Answers1

0

The documentation has your solution at: https://parse.com/docs/cloud_code_guide#functions

For GET requests you have to use the request.params object which has all your request parameters for a GET are there. POSTS are sent in the request body, GET in the request parameters.

It looks like you are trying to get the params you can use something similar to:

Parse.Cloud.define("myMethod", function(request, response) {
  if(request.params.myparam == "moo") {
    response.success("Cow!");
  }
  else {
    response.error("Unknown type of animal");
  }
});
MiltoxBeyond
  • 2,683
  • 1
  • 13
  • 12