Call a cloud function from within Unity C#

I couldn’t find any syntax reference to call a cloud function from within Unity using C# script.

If you can make a http request then you can call them as REST

1 Like

As you said @cryptokid , I am supposed to call it in the following format?

https://MY_DAAP_URL.moralis.io:2053/server/functions/MY_FUNCTION_NAME?_ApplicationId=MY_APPLICATION_ID&MY_PARAMETER_NAME=MY_PARAMETER_VALUE

I tried to run it in the browser, but it says, ā€œ{ā€œcodeā€:141,ā€œerrorā€:ā€œInvalid function: ā€œTestFuntionā€ā€}ā€

Do you have that cloud function named TestFunction?

yes the function is there which I am trying to call.

Maybe is a typo, can you double check the function name?

1 Like

You are right it was a typo. Solved it, the function was defined as a ā€œjobā€ not as normal ā€œdefineā€ function.

1 Like

What if in any case I want to get user details(request.user) in the cloud function through REST API call?
Is there any way to do so?

It may be if you also send the session token in that REST api call, you can look on how a call to a cloud function looks like in vanilla js

Sending session token with REST api? Can you please elaborate?

you can send in headers or parameters, I don’t know the exact syntax, you can check the exact syntax by doing a simple request in vanilla js with the SDK

const ratings = await Moralis.Cloud.run("averageStars", params);

This is what it looks like when calling moralis cloud function in vanilla js.
Referenced the from moralis cloud function docs.

I mean, to look in network tab to see how the request looks like, the exact request that is equivalent of using REST

You can pass in some user detail as params when you call via REST API and query for the user object inside that cloud function.

const ratings = await Moralis.Cloud.run(ā€œaverageStarsā€, params);

If you use the JavaScript SDK and the user has authenticated, the user object will be available with request.user inside your cloud function.

Yaa I was working with the same sense. I passed objectId to query in the DB for the same but it returns empty array.

const query = new Moralis.Query("_User");
query.equalTo("username", "JBmUAjNE----------O2cVGf0");
const res = await query.find();

Here is my code for the query to the DB. _User is the className in which I’m trying to check the column of username for the given username-> JBmUAjNE----------O2cVGf0.
Is there something I’m doing wrong.

Did you solve this with the use of masterKey?

Yes its solved with the use of masterKey?