Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unable to access the CloudSave API with service account accessToken.

Discussion in 'Cloud Save' started by CM_RDX, Mar 21, 2023.

  1. CM_RDX

    CM_RDX

    Joined:
    Jan 26, 2023
    Posts:
    11
    Hello
    I am currently struggling with the problem already described in the title.
    My use case is that i want to write player data on the server using a service account accessToken.
    Following the CloudSave API documentation my request looks something like this:

    curl -H "Authorization: Bearer <Generated accessToken>" 
    -X GET https://cloud-save.services.api.unity.com/v1/data/projects/<ProjectID>/players/<PlayerID>/items

    The error respone i am getting is the following:
    {"type":"problems/basic","title":"Error","status":400,"detail":"EnvironmentID not set","instance":null,"code":1003}

    Our project features both a production and develeopment environment. I tried generating the access token with either environment ID's but come to the same result. Is there by any chance a custom header that has to be set or an additional parameter that is not mentioned in the documentation, where i would have to pass the environment ID?

    The error response samples in the documentation also lead to no clue, as every error code response sample contains the same example error.

    Any help is greatly appreciated.
    Thanks,
    Chris
     
  2. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    29
    Hi VitaminBepis.

    I replied to your other thread. I believe your access token might not contain the environment Id as you suspect it does. You could decode the token on https://jwt.io and see if there is an attribute in the token called "envId". The token should look something like the following for it to be a valid token to call Cloud Save

    Code (Boo):
    1. {
    2.   "exp": 1679482374,
    3.   "iat": 1679478774,
    4.   "nbf": 1679478774,
    5.   "jti": "<JTI>",
    6.   "sub": "<SUB>",
    7.   "version": 1,
    8.   "iss": "https://services.unity.com",
    9.   "aud": [
    10.     "upid:<PROJECT_ID>",
    11.     "envId:<ENVIRONMENT_ID>"
    12.   ],
    13.   "scopes": [
    14.     ...
    15.   ],
    16.   "apiKeyPublicIdentifier": "<apiKeyId>"
    17. }
    If you could provide an example of how you are calling the token-exchange API, I would be able to assist further.
     
  3. CM_RDX

    CM_RDX

    Joined:
    Jan 26, 2023
    Posts:
    11
    Hi Francois,
    You are right, I checked the contents of the token on https://jwt.io and in fact it does not contain the "envId" attribute.

    I call the token-exchange API like this:
    Code (Boo):
    1. curl -X POST -H "Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS>" https://services.api.unity.com/auth/v1/token-exchange?projectId=<PROJECT_ID>&environmentId=<ENVIRONMENT_ID>
    As far as I can tell everything should be correct (double checked the ID's as well as service account credentials).
     
  4. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    29
    I've sent you a DM for your project and org id so that I can have a deeper look into our systems.
     
  5. NielsF

    NielsF

    Joined:
    Mar 10, 2022
    Posts:
    1
    Hi,
    Same issue here.

    the token is well generated by the request to token-exchange but doesn't contain the envId so impossible to use it.
    Is that a global issue or linked to something on the project?

    thanks,
     
  6. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    29
    Hi NielsF,

    When you call the token-exchange API, make sure that the projectId and environmentId is in the query parameters like so:

    Code (Boo):
    1.     curl -X POST -H "Authorization: Basic <ENCODED_SECRET>"  'http://services.api.unity.com/auth/v1/token-exchange?projectId=<projectId>&environmentId=<environmentId>'
    2.  
    That should generate a token with the environmentId and projectId in the `aud` claim of the token.

    Let me know if that doesn't work and I can follow up with you via DM.