Calling a cloud function using API when param includes a number

Hi guys, great work with the forum!

Iโ€™m trying to call a cloud function via REST API which requires two parameters.
When I call the function I am getting no results because the server is converting my number parameter to a string in the Input object

Example 1
If I run the cloud function from front end of app like this:

await"testFunction",{name:"MP", number:5})

The logs display:

Input: {"name":"MP","number":5}
Result: [Loads of results, working normally]

Example 2 -
If I convert my cloud function into an API call and have something like this:


The logs display:

Input: "_ApplicationId":"MYAPPID","name":"MP","number":"5"}
Result: []

I notice that the function returns nothing because the number param is going through as a string and not a number.

Is there a simple way around that?

you could convert it back to a number in that cloud function

I experimented with the field validation, but it errors because the number field is not a number, itโ€™s going through as a string

Moralis.Cloud.define("testFunction", async (request) => {
  const unitQuery = new Moralis.Query("Unit");
  unitQuery.greaterThan(, request.params.number);
  const tokenResult = await unitQuery.find();
  const results = => token.attributes);
  return results;
  fields : {
    name : {
      required: true,
      options: name => {
        return name.length > 1;
      error: "Test error message"
    number : {
      type: Number,
fetch('').then(so on and so on)

then you can send it as string in both cases, and validate it as string, or use only one of those two methods of calling the cloud function

Ok yep, both issues can be marked as resolved

Iโ€™ll add some conditionals in the cloud function to convert my params to the data type I need
Iโ€™ll edit my validation

Thanks again
(world class support)

1 Like