question

Octolust avatar image
Octolust asked

GrantItemsToUsers with json data

i make a call to grant an item from cloud

var result = {Data:[]};
var obj = {};
	obj.Stat = "Stat";
	obj.Type = "Type";
	obj.Value = Math.floor(Math.random() * 100 + 1);
	result.Data.push(obj);
 var grantItemsRequest = 
{ 
	CatalogVersion: ITEM_CAG, 
	ItemGrants:
		[{ PlayFabId: currentPlayerId, 
		Annotation: "getRandom", 
		ItemId: "itemId", 
		Data: 
			{ "Data": JSON.stringify(result) }
		}] 
}; 

server.GrantItemsToUsers(grantItemsRequest);

is Error.

So how fix it? It need add slashs?

Updated

CloudScript
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.

Seth Du avatar image Seth Du ♦ commented ·

Do you have any error report?

Directly from your code, the obvious incorrect is the catalog version, please try this if ITEM_CAG is not a variable:

CatalogVersion: "ITEM_CAG",
0 Likes 0 ·
Octolust avatar image Octolust Seth Du ♦ commented ·

@SethDu

i had updated info at Replies.

ITEM_CAG just string name of catalog

var ITEM_CAG = "Items";
0 Likes 0 ·
Octolust avatar image Octolust Octolust commented ·
@SethDu

I think i found solution. The string in request too large???

i use

var grantItemsRequest = {        
        CatalogVersion: ITEM_CAG,
     	ItemGrants:[{
        	PlayFabId: currentPlayerId,
         	Annotation: "getRandomRune",
        	ItemId: "RuneFrag",
     		Data: {
        		"Data": "122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221312312312 123123123121232222222222222222222222222222222222222222222222222222222222222222,33333333333322222222222222222222222222222222222222222222222222222222222221312312312 123123123121232222222222222222222222222222222222222222222222222222222222222222,33333333333322222222222222222222222222222222222222222222222222222222222221312312312 123123123121232222222222222222222222222222222222222222222222222222222222222222,33333333333322222222222222222222222222222222222222222222222222222222222221312312312 123123123121232222222222222222222222222222222222222222222222222222222222222222,33333333333333",        	
      		} 
        }]     	
    };

It error but with a smaller string it ok?
But why?

0 Likes 0 ·
Seth Du avatar image
Seth Du answered

I have tested the provided code and your codes seem to work fine. I also get errors for the 3rd part of the hard-coded data (testing result is the same as yours, first 2 works fine) but the detailed error is returned and it is due to exceeding the Inventory item data value size Limits, which means the custom data value in an inventory item can only be 100 bytes. If you are looking for increasing the maximum size of data value, you need to upgrade your plan. If this error occurs, you should be able to observe it in PlayStream Event.

For more information about Limits, please navigate to [Game Manager] ->[Settings] ->[Limits]

10 |1200

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

Octolust avatar image
Octolust answered

Update : i replace

"Data": JSON.stringify(result)


with

"Data": "{\"Data\":[{\"Stat\":\"Int\",\"Type\":\"Add\",\"Value\":84}]}",

it work;

"Data": "{\"Data\":[{\"Stat\":\"Int\",\"Type\":\"Add\",\"Value\":84},{\"Stat\":\"Str\",\"Type\":\"Add\",\"Value\":-51}]}",

it work;

"Data": "{\"Data\":[{\"Stat\":\"Int\",\"Type\":\"Add\",\"Value\":84},{\"Stat\":\"Str\",\"Type\":\"Add\",\"Value\":-51},{\"Stat\":\"End\",\"Type\":\"Add\",\"Value\":30}]}",

it get ERROR;

how?

10 |1200

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

Octolust avatar image
Octolust answered

Hav error at line

  1. server.GrantItemsToUsers(grantItemsRequest);

this log error when i run it

{
    "FunctionResult": null,
    "Logs": [
        {
            "Level": "Error",
            "Message": "PlayFab API request error",
            "Data": [
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ],
                        [
                            [
                                [
                                    [
                                        []
                                    ],
                                    [
                                        []
                                    ],
                                    [
                                        []
                                    ],
                                    [
                                        [
                                            [
                                                []
                                            ],
                                            [
                                                []
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            [
                                [
                                    [
                                        []
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        }
    ],
    "ExecutionTimeSeconds": 0.052923,
    "MemoryConsumedBytes": 119008,
    "APIRequestsIssued": 2,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "CloudScriptAPIRequestError",
        "Message": "The script called a PlayFab API, which returned an error. See the Error logs for details.",
        "StackTrace": "Error\n    at handlers.runfunction(4E22F-main.js:163:9)"
    }
}                            
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.