Skip to content

Cloud Code Response Error #517

Closed
Closed

Description

@YousefAlsbaihi

New Issue Checklist

Issue Description

I create a cloud function that create users and i called it using PHP, not it's creating users fine and all good in Parse
but the response is not there, all i get is error

A PHP Error was encountered
Severity: Warning

Message: Undefined array key "result"

Filename: Parse/ParseCloud.php

Line Number: 40

Steps to reproduce

Create a cloud function using this code

Parse.Cloud.define("createNewUser", async (request) => {
    var User = Parse.Object.extend("User");
    var us = new User();
    us.set("username", request.params.username);
    us.set("name", request.params.name);
    us.set("email", request.params.email);
    us.set("password", request.params.password);
    await us.save()
        .then((user) => {
            // Execute any logic that should take place after the object is saved.
            return ('New object created with objectId: ' + user.id);
        }, (error) => {
            // Execute any logic that should take place if the save fails.
            // error is a Parse.Error with an error code and message.
            return ('Failed to create new object, with error code: ' + error.message);
        });
});


// To Run the code in PHP 

$rating = ParseCloud::run("newUser", $userData);


Actual Outcome

Error as explained before

Expected Outcome

fail or success message

Environment

Parse PHP SDK

  • SDK version: 2.3.2
  • PHP version: 8.2.0

Server

  • Parse Server version: 6.2.1
  • Operating system: Ubuntu 20
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Digital Ocean

Database

  • System (MongoDB or Postgres): MongoDb
  • Database version: 6
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Logs

A PHP Error was encountered
Severity: Warning

Message: Undefined array key "result"

Filename: Parse/ParseCloud.php

Line Number: 40

Backtrace:

File: /Applications/MAMP/htdocs/scr/application/third_party/parse/vendor/parse/php-sdk/src/Parse/ParseCloud.php
Line: 40
Function: _error_handler

Activity

  1. parse-github-assistant commented on Aug 10, 2023

    @parse-github-assistant

    Thanks for opening this issue!

    • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
  2. YousefAlsbaihi commented on Aug 10, 2023

    @YousefAlsbaihi
    Author

    It's resolved,
    it turned out that i have to return the whole save() function, so the cloud code would be:

    Parse.Cloud.define("createNewUser", async (request) => {
        var User = Parse.Object.extend("User");
        var us = new User();
        us.set("username", request.params.username);
        us.set("name", request.params.name);
        us.set("email", request.params.email);
        us.set("password", request.params.password);
        return await us.save();
    });
    

    i'm not sure if this is secure or not, but managed to get objectId and Error messages if there is any,
    however i was confused of the example here

    Parse.Cloud.define("averageStars", async (request) => {
      const query = new Parse.Query("Review");
      query.equalTo("movie", request.params.movie);
      const results = await query.find();
      let sum = 0;
      for (let i = 0; i < results.length; ++i) {
        sum += results[i].get("stars");
      }
      return sum / results.length;
    });
    

    this example return a string, how Parse Cloud Php would get result from that ?
    i haven't tested that example but just observation.

    if there is a different approach, i would appreciate it please let me know.

  3. mtrezza commented on Aug 15, 2023

    @mtrezza
    Member

    A Cloud Function can return any type, if I'm not mistaken, it doesn't even have to be a JSON. It then depends on your implementation client side to properly handle the response. So the Parse PHP SDK should not expect a certain type for a Cloud Function response.

  4. mtrezza commented on Aug 15, 2023

    @mtrezza
    Member

    I'm closing this as it does not seem to be a Parse PHP SDK issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions