Call from Unity game server (Multiplay Hosting)
Invoke module endpoints from a dedicated game server using Multiplay Hosting.
Read time 1 minuteLast updated 18 hours ago
You can call a module endpoint from a dedicated game server using Multiplay Hosting.
Prerequisites
- The game server you are invoking Cloud Code from and any related resources must exist in the same Unity Dashboard project and environment.
- Onboard with Multiplay Hosting.
Call out to Cloud Code
Follow the steps below to call out to a Cloud Code module endpoint from a game server.Authentication
You can authenticate requests using a Multiplay Hosting token or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header.Authenticate using a Multiplay Hosting token
See the Game Server Documentation here.Authenticate using a stateless token
To use a stateless token, you need to create a service account and call the Token Exchange API. Refer to authenticating trusted clients for the Cloud Code Client API.Call a module endpoint
You can call a module endpoint using any HTTP library that is native to the codebase. Use the retrieved authentication token as a bearer token for HTTP authentication in the request header. An example CURL request to call an endpoint using the Cloud Code API could look like this:curl -X POST -H "Authorization: Bearer <BEARER_TOKEN>" 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/<MODULE_NAME>/<FUNCTION_NAME>'