Search code examples
node.jsparse-platformparse-cloud-code

How do I return a value from Parse Cloud Code to my iOS app?


Trying to understand cloud code on my self-hosted Parse server.

I'm trying to call my cloud code function in Swift, pass it a parameter, and then return that from cloud code to my application to print. ISSUE: I don't know what the code on Parse Cloud Code looks like to return the parameter sent to it. I have tried this and no luck...

Parse.Cloud.define('hello', function(req, res) {
    res.success(request.params['test']);
 });

Here is my Swift code...

PFCloud.callFunctionInBackground("hello", withParameters: ["test":"tester"]) {
        (response: AnyObject?, error: NSError?) -> Void in
        if error == nil {
            let responseString = response as? String
            print(responseString)
        } else {
            print(error!.description)
        }
    }

Could anybody help me out here? With the code above, I get this error from print(error!.description)...

2016-05-01 17:51:32.031 TestApp[662:151287] [Error]: {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.13.0) Error Domain=Parse Code=1 "{"code":1,"message":"Internal server error."}" UserInfo={error={"code":1,"message":"Internal server error."}, NSLocalizedDescription={"code":1,"message":"Internal server error."}, code=1}


Solution

  • This doesn't look like an issue with iOS but rather with your Cloud Code. The "Internal server error" message indicates a problem on the server.

    Looking at the Cloud Code you posted, you're referencing request.params['test'] but the request object is defined as req in your function parameters. Change request.params['test'] to req.params['test'] and you should be good to go.