Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Official External Services access from Cloud Code

Discussion in 'Cloud Code' started by MaximeDelecourt, Sep 20, 2022.

  1. MaximeDelecourt


    Unity Technologies

    Oct 21, 2021
    Cloud Code now allows access to external services!

    You can now mix and match any UGS service through public API or Cloud Code SDK with your own existing tools and services. This should unlock a lot of exciting use cases and make it easier for you to migrate to UGS while retaining access to services you cannot do without.

    We are working on an update to our documentation, in the meantime here is some sample code that calls out to the Cloud Save public API:

    Code (JavaScript):
    1. const axios = require("axios")
    3. module.exports = async ({ params, context, logger }) => {
    4.     let config = {
    5.         headers: {
    6.             Authorization: `Bearer ${context.accessToken}`
    7.         }
    8.       };
    9.     let url = `${context.projectId}/players/${context.playerId}/items?keys=HEALTH`;
    10.     let result = await axios.get(url, config);
    11.     return;
    12. };
    We’re always looking to improve Cloud Code based on your feedback. Please don’t hesitate to post feature requests, questions and interesting use cases for us and others to consider.
    Last edited: Sep 20, 2022
  2. Dknighter2


    Aug 17, 2014
    Hey, can you please confirm that this is working?

    We've tried this ourselves and get a 404 error.
  3. MariusUrbelis


    Unity Technologies

    Mar 15, 2015
    Hi. If you run this sample as a Cloud Code script in the Dashboard, even if a given player (playerId) does not have the HEALTH item in their Cloud Save, you should receive this response:

    Code (JavaScript):
    1. {
    2.   "links": {
    3.     "next": null
    4.   },
    5.   "results": []
    6. }
    A 404 might occur if the url is incorrect for example .../items?keys=HEALTH endpoint call is changed to .../itemz?keys=HEALTH

    However, this same example above can be done with Cloud Save SDK for Cloud Code.

    Code (JavaScript):
    1. const { DataApi } = require("@unity-services/cloud-save-1.2");
    3. module.exports = async ({ params, context }) => {
    4.   const { projectId, playerId } = context;
    6.   const cloudSaveAPI = new DataApi(context);
    8.   const response = await cloudSaveAPI.getItems(projectId, playerId, "HEALTH");
    10.   return;
    11. };
    this code should return the above mentioned response.
  4. Kazoos


    Nov 28, 2012
    I can't seem to locate in the docs or within the web console where you can set secrets which can be used. I am working with Supabase and need to pass in keys to my requests and most certainly don't want this embedded in the code.
  5. samg-unity


    Unity Technologies

    Mar 23, 2021
    Hi @Kazoos

    As you've noticed thats a key feature that we're currenty missing so I'm very happy to say that we are working on secret management functionality for Cloud Code!