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 id.unity.com 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

    MaximeDelecourt

    Unity Technologies

    Joined:
    Oct 21, 2021
    Posts:
    21
    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")
    2.  
    3. module.exports = async ({ params, context, logger }) => {
    4.     let config = {
    5.         headers: {
    6.             Authorization: `Bearer ${context.accessToken}`
    7.         }
    8.       };
    9.     let url = `https://cloud-save.services.api.unity.com/v1/data/projects/${context.projectId}/players/${context.playerId}/items?keys=HEALTH`;
    10.     let result = await axios.get(url, config);
    11.     return result.data;
    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

    Dknighter2

    Joined:
    Aug 17, 2014
    Posts:
    44
    Hey, can you please confirm that this is working?

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

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    49
    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");
    2.  
    3. module.exports = async ({ params, context }) => {
    4.   const { projectId, playerId } = context;
    5.  
    6.   const cloudSaveAPI = new DataApi(context);
    7.  
    8.   const response = await cloudSaveAPI.getItems(projectId, playerId, "HEALTH");
    9.  
    10.   return response.data;
    11. };
    this code should return the above mentioned response.
     
  4. Kazoos

    Kazoos

    Joined:
    Nov 28, 2012
    Posts:
    19
    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

    samg-unity

    Unity Technologies

    Joined:
    Mar 23, 2021
    Posts:
    50
    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!