Cloud Code function with one parameter

If I only pass one parameter { userId: ‘test’ } to a cloud function:

/**
 * @param {String} userId
 */ 
 async testFunction(userId) { return userId }

It would return “{\“userId\”:\“test\”}” instead of ‘test’

And in a query it would be: user.objectId = ‘{\“userId\”:\“test\”}’ which makes the query not working.

However if I pass two parameters { userId: ‘test’, placeholder: ‘placeholder’ } then everything is normal and userId would be a string as expected.

/**
 * @param {String} userId
 * @param {String} placeholder
 */ 
 async testFunction(userId, placeholder) {}

Hi @Barry,

This behavior is expected and is related to how Backendless handles Cloud Code function parameters.

When a function has only one parameter , the request body must contain a raw value , not a JSON object.
So instead of:
{ “userId”: “test” }

it should be:
“test”

In this case, "test" is passed directly as the userId argument.

However, when a function has multiple parameters , the request body must be a JSON object, for example:
{
“userId”: “test”,
“placeholder”: “placeholder”
}

I’ve attached screenshots showing where you can find the expected request format for Cloud Code calls.


Regards,
Sergey

Thanks for the detailed explanation Sergey

1 Like