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.

Question Troubleshoot HttpException`1: HTTP/1.1 400 Bad Request

Discussion in 'Cloud Save' started by OUTERDARKNESS, Aug 29, 2022.



    Feb 27, 2013
    Hello, when using Cloud Save, I get an error HttpException`1: HTTP/1.1 400 Bad Request.
    The data I am sending is a string created by serialization of an object containing primitive datatypes (int, float, bool, string). The JSON serialization appears valid (attached), I don't see any red flags looking at the data.

    What is the best way to troubleshoot this? Are there certain characters that are invalid that I need to look out for?

    Unity Editor ver: 2021.3.3f1 / Windows
    Cloud Save ver: 2.0.1

    Code (CSharp):
    1. string payload = JsonUtility.ToJson(SceneState);
    2. var dataCollection = new Dictionary<string, object> { { key, payload } };
    3. await CloudSaveService.Instance.Data.ForceSaveAsync(dataCollection);

    Error Log:
    CloudSaveValidationException: There was a validation error. Check 'Details' for more information.
    HttpException`1: HTTP/1.1 400 Bad Request
    Unity.Services.CloudSave.Internal.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.CloudSave.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/
    Unity.Services.CloudSave.Internal.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.CloudSave.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/
    Unity.Services.CloudSave.Internal.Apis.Data.DataApiClient.SetItemBatchAsync (Unity.Services.CloudSave.Internal.Data.SetItemBatchRequest request, Unity.Services.CloudSave.Internal.Configuration operationConfiguration) (at Library/PackageCache/
    Unity.Services.CloudSave.ApiClient.ForceSaveAsync (System.Collections.Generic.Dictionary`2[TKey,TValue] data) (at Library/PackageCache/
    Unity.Services.CloudSave.SaveDataInternal.ForceSaveAsync (System.Collections.Generic.Dictionary`2[TKey,TValue] data) (at Library/PackageCache/
    Rethrow as CloudSaveValidationException: There was a validation error. Check 'Details' for more information.
    Unity.Services.CloudSave.SaveDataInternal.ForceSaveAsync (System.Collections.Generic.Dictionary`2[TKey,TValue] data) (at Library/PackageCache/
    CloudData.SaveData (System.String key, System.Object data, CloudData+OnReturn_Empty callback) (at Assets/01_Scripts/User/CloudData.cs:59)
    System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <6073cf49ed704e958b8a66d540dea948>:0)
    UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
    UnityEngine.UnitySynchronizationContext.Exec () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
    UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <f1212ad1dec44ce7b7147976b91869c3>:0)

    Attached Files:

  2. MileyUnity


    Unity Technologies

    Jan 3, 2020
    Hi there,

    Whilst the error isn't all that clear, I think it means that your data is too big. The CloudSave SDK serializes the incoming objects to json for you and given that you are sending in a string rather than an object it will have to re-serialize it in order to make it transmittable via json. This means that your 14.6Kb json string may end up being over the 16Kb limit per slot and thus causing the 400 bad request.

    It would be best to avoid using the JsonUtility to serialize your outgoing data and instead put in the object itself and let CloudSave take care of the serialization. I would also recommend to look into a different way of storing your data as you may easily go over the 16Kb limit per slot and would again get a 400 bad request response.
    SebT_Unity likes this.


    Feb 27, 2013
    Bingo! You are correct, the serialization of the string was adding escape characters to all quotes, inflating the files size past the limit. I was able to split up the data into smaller chunks to meet the requirement. Thanks for your help.

    BTW, I've been using JsonUtility because the Newtonsoft serializer used by Cloud Save breaks when trying to serialize a Vector3.

    JsonSerializationException: Self referencing loop detected for property 'normalized' with type 'UnityEngine.Vector3'
  4. 8bitgoose


    Dec 28, 2014
    I had the exact same error however it seems you can't fetch keys from the Unity Service that don't exist. So I asked for a key that doesn't exist and I got a bad error code.

    Shouldn't Unity just send me no information back with that key or not include it in the resulting dictionary? Is this intentional? Do I need to validate every key I send up to the Cloud?