question

elangkamp avatar image
elangkamp asked

Sending Json data to custom API not receiving entire body

    if(args.mechs == null)
    {
        return "No data sent";
    }
    
    var body = {
    };


    var url = "https://api.averongame.com/v1/mechs/damage/" + currentPlayerId;
    var content = args.mechs.toString();
    var httpMethod = "Post";
    var contentType = "application/json";


    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, headers);
    return response + " data: " + args.mechs.toString();;



{"Message":"Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'AveronAPI.DTO.MechUpdateRequest' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1.| 



Request: [{\"critType\":0,\"weaponIndex\":-1,\"hits\":0,\"active\":true}],\"weapons\":[{\"weaponType\":\"Test Weapon 0\",\"location\":1,\"damage\":0,\"heat\":0,\"minRange\":0,\"shortRange\":0,\"mediumRange\":0,\"longRange\":0,\"ammoType\":\"Test Ammo Type 0\",\"activeFire\":false,\"weaponActive\":false,\"clusterWeapon\":false,\"clusterNumber\":0,\"baseToHit\":0},{\"weaponType\":\"Test Weapon 1\",\"location\":5,\"damage\":0,\"heat\":0,\"minRange\":0,\"shortRange\":0,\"mediumRange\":0,\"longRange\":0,\"ammoType\":\"Test Ammo Type 1\",\"activeFire\":false,\"weaponActive\":false,\"clusterWeapon\":false,\"clusterNumber\":0,\"baseToHit\":0}],\"ammos\":[{\"ammoType\":\"Test Ammo Type 0\",\"ammoCount\":0,\"capacity\":10,\"explosive\":false,\"location\":6},{\"ammoType\":\"Test Ammo Type 0\",\"ammoCount\":0,\"capacity\":10,\"explosive\":false,\"location\":8}]}]}"} 



data: {"mechs":[{"id":77,"mechClass":0,"name":"Test Mech 0","mechType":"","tonnage":0,"walkMP":0,"runMP":0,"jumpMP":0,"heat":0,"heatSinks":0,"doubleHeatSinks":false,"sensorRange":0,"leftArmArmor":0,"rightArmArmor":5,"leftTorsoArmor":5,"rightTorsoArmor":0,"centerTorsoArmor":5,"leftTorsoRearArmor":0,"rightTorsoRearArmor":0,"centerTorsoRearArmor":0,"headArmor":5,"leftLegArmor":0,"rightLegArmor":0,"leftArmInternal":2,"rightArmInternal":2,"leftTorsoInternal":2,"rightTorsoInternal":2,"centerTorsoInternal":2,"headInternal":2,"leftLegInternal":2,"rightLegInternal":2,"headCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"centerTorsoCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"rightTorsoCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"leftTorsoCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"rightArmCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"leftArmCrit":[],"rightLegCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"leftLegCrit":[{"critType":0,"weaponIndex":-1,"hits":0,"active":true}],"weapons":[{"weaponType":"Test Weapon 0","location":1,"damage":0,"heat":0,"minRange":0,"shortRange":0,"mediumRange":0,"longRange":0,"ammoType":"Test Ammo Type 0","activeFire":false,"weaponActive":false,"clusterWeapon":false,"clusterNumber":0,"baseToHit":0},{"weaponType":"Test Weapon 1","location":5,"damage":0,"heat":0,"minRange":0,"shortRange":0,"mediumRange":0,"longRange":0,"ammoType":"Test Ammo Type 1","activeFire":false,"weaponActive":false,"clusterWeapon":false,"clusterNumber":0,"baseToHit":0}],"ammos":[{"ammoType":"Test Ammo Type 0","ammoCount":0,"capacity":10,"explosive":false,"location":6},{"ammoType":"Test Ammo Type 0","ammoCount":0,"capacity":10,"explosive":false,"location":8}]}]}
<br>
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

elangkamp avatar image elangkamp commented ·

as you can see the data that's being sent is much longer than the data that's being received in the request. Is there some sort of limit on the outgoing data?

0 Likes 0 ·
Sarah Zhang avatar image
Sarah Zhang answered

Do you mean you sent the Http POST request to your custom API on PlayFab CloudScript? Your code looks like it. We tested that sending your sample JSON that after “data:” to our custom API for the test. The test webserver just gives a response whose content is what we sent when we sent a valid string. Actually, we are unable to convert a JSON Object to string when we use args.mechs.toString(); on CloudScript. When we use return args.mechs.toString(); it returned [object object]. When we use JSON.stringify(body) instead of args.mechs.toString(), it returned a complete JSON Array [{\"id\":77,……..\"location\":8}]}]. And response is the same content.

About the limits. If we are in the free tier, Cloud Script arguments size limit is 30,000 bytes. In your selected Title, you can navigate to [Settings]->[Limits] to check it. However, in your case, even if there is a limit on the outgoing data, it should have no effect on the sample data’s completeness. And after we got the response, we found it is a Json Array. We can also see your Error Message said “Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'AveronAPI.DTO.MechUpdateRequest' because the type requires a JSON object”. Maybe you can check it to find some workarounds.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

elangkamp avatar image elangkamp commented ·

The request is the string that is received by the API the data is what was received by playfab from my game. Somewhere between playfab and the api it's clipping that string.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang elangkamp commented ·

If we are in the free tier, the Cloud Script arguments size limit is 30,000 bytes. If you are in other tiers, in your selected Title, you can navigate to [Settings]->[Limits] to check if your arguments over the limit. If they don't over the limit, this issue may be caused by other reasons.

0 Likes 0 ·
elangkamp avatar image elangkamp Sarah Zhang commented ·

Good news, I found out that it's not playfab causing the issue. For some reason my API is cutting off the first several hundred characters of the json from the body of the request. Not sure why yet.

0 Likes 0 ·
elangkamp avatar image
elangkamp answered

This was not a Playfab issue it was a deserialization issue on the AWS side.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.