question

Kijpmarn Engkapawastr avatar image
Kijpmarn Engkapawastr asked

Getting item,How to get ItemInstanceId in GrantItemsToUse

I try to use GrantItemsToUser then use ItemInstanceId for UpdateUserInventoryItemCustomData

but I couldn't get.

Here is part of my code.

var g_response = http.request(g_url,method,g_contentBody,contentType,headers);
    log.info(g_response);
/*
"Message": "{
	\"code\":200,
	\"status\":\"OK\",
	\"data\":{
		\"ItemGrantResults\":[{
			\"PlayFabId\":\"BA52D6113E697FE7\",
			\"Result\":true,
			\"ItemId\":\"TestWeapon\",
			\"ItemInstanceId\":\"17A70BA49E494F2A\",
			\"ItemClass\":\"two-handed sword\",
			\"PurchaseDate\":\"2019-07-19T09:26:58.434Z\",
			\"CatalogVersion\":\"Item\",
			\"DisplayName\":\"DivideTester\",
			\"UnitPrice\":0
		}]
	}}"
*/
    var ItemInstanceId = g_response.data.ItemGrantResults.ItemInstanceId
/*
"Error": {
   "Error": "JavascriptException",
   "Message": "JavascriptException",
   "StackTrace": "TypeError: Cannot read property 'ItemGrantResults' of undefined\n    at handlers.grantItem (A963F-main.js:378:28)"
  }
*/
,

So I try to use GrantItemsToUser then get ItemInstanceId for UpdateUserInventoryItemCustomData.

Both of my function is work properly separately but I can't get ItemInstanceId if I want to use UpdateUserInventoryItemCustomData for my new item that's from GrantItemsToUser.

Here is part of my code

    var g_response = http.request(g_url,method,g_contentBody,contentType,headers);
    log.info(g_response);
/*
This is message from log.info(g_response)
"{\"code\":200,
  \"status\":\"OK\",
  \"data\":{
	\"ItemGrantResults\":[{
		\"PlayFabId\":\"BA52D6113E697FE7\",
		\"Result\":true,
		\"ItemId\":\"TestWeapon\",
		\"ItemInstanceId\":\"7034E46772904961\",
		\"ItemClass\":\"two-handed sword\",
		\"PurchaseDate\":\"2019-07-19T09:09:16.505Z\",
		\"CatalogVersion\":\"Item\",
		\"DisplayName\":\"DivideTester\",
		\"UnitPrice\":0
}]}}"


*/
    var ItemInstanceId = g_response.data.ItemGrantResults.ItemInstanceId //didn't work
/*
"Error": {
   "Error": "JavascriptException",
   "Message": "JavascriptException",
   "StackTrace": "TypeError: Cannot read property 'ItemGrantResults' of undefined\n    at handlers.grantItem (A963F-main.js:378:28)"
  }
*/
   

Any idea how to make it work?

apisCloudScriptIn-Game EconomyPlayer Inventory
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.

Kijpmarn Engkapawastr avatar image Kijpmarn Engkapawastr commented ·

Sorry, I thought my question didn't save when I signed in so I type it again.

0 Likes 0 ·

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi, according to the Docs, it seems that the “g_response.data.ItemGrantResults” in your codereturns a list of ItemGrantResult, in each of them contains the ItemInstanceId. You may have to parse one of the results to get it, I just tried to get it via C# code and it worked fine. You can have a try via JS code by doing this: var ItemInstanceId = g_response.data.ItemGrantResults[0].ItemInstanceId. Any issues please let me know:)

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]