question

Andrei Cibotaru avatar image
Andrei Cibotaru asked

server.GrantItemsToUser

Hi,
I am using GrantItemsToUser on the cloud script. I do get a positive response but no items are added to the user's inventory.

Here is a sample of the output I get. The only difference I see, from the result returned by the example request in the documentation, is that the Result field is true, as opposed to the false i get.

"messageValue": "{\"ItemGrantResults\":[{\"PlayFabId\":\"...\",\"Result\":false,\"ItemId\":\"item1\",\"Annotation\":\"Start Game Items\",\"UnitPrice\":0} ... }

Any ideas on what am I doing wrong?

Kind regards,
Andrei

10 |1200

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

brendan avatar image
brendan answered

Looking at your title, I see the issue. The problem is that you're specifying an item which does not exist in the default catalog. If you need to do that, you'll need to specify the CatalogVersion in the call.

We do recommend though that you use one catalog version for your game, and use the Stores for subdivisions for different item types or user classes (that can only purchase certain items). The "version" on the catalog is literally intended to be that - a version ID, which is associated with a particular version of your released game.

10 |1200

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

Andrei Cibotaru avatar image
Andrei Cibotaru answered

I forgot to mention the fact that I am running in testing mode. The cloudscript has not been deployed to live.

10 |1200

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

brendan avatar image
brendan answered

Can you let us know what the parameters you are that you're passing into this call? Also, if you try the same call in Postman, do you get a successful result?

10 |1200

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

Andrei Cibotaru avatar image
Andrei Cibotaru answered

This is the reply I get from Playfab using Postman. From what I can tell it is successful, but I don't see the items in the inventory. Here is the reply from the server using Postman:

{
"code": 200,
"status": "OK",
"data": {
"ItemGrantResults": [
{
"PlayFabId": "[playfabID]",
"Result": false,
"ItemId": "[itemID]",
"Annotation": "Start Game Items",
"UnitPrice": 0
}
]
}
}

And this is the url i send in:

POST /Server/GrantItemsToUser HTTP/1.1
Host: [titleID].playfabapi.com
Content-Type: application/json
X-SecretKey: [secretKey]
Cache-Control: no-cache

{ "PlayFabId" : "[playerID]" , "Annotation" : "Start Game Items" , "ItemIds" : ["[itemID]"] }
On the other hand, the cloudscript uses this request:

var result = server.GrantItemsToUser( {PlayFabId : currentPlayerId, Annotation : "Start Game Items" , ItemIds : [ "[itemID]" ] });

And the reply is :

{
"messageValue": "{\"ItemGrantResults\":[{\"PlayFabId\":\"[playfabID]\",\"Result\":false,\"ItemId\":\"[itemID]\",\"Annotation\":\"Start Game Items\",\"UnitPrice\":0}]}"
}

Note: I have reviewed the values of [secretKey],[titleID], [itemID] and [playfabID] and seem legit.

Thanks in advance.

Kind regards,
Andrei

10 |1200

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

Nate McDorman avatar image
Nate McDorman answered

Hi there,

I was having this same issue, but adding the catalog version to the call was what fixed it for me. Can you please update the documentation for whenever a catalog version needs to be specified to avoid use of the "default catalog"? Also, I'm not able to set any catalogs as the primary via the "Set As Primary Catalog" button. It is unresponsive. :(

10 |1200

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

brendan avatar image
brendan answered

Thanks, we'll work to make the docs more clear. For the "Set as Primary" issue, could you let us know exactly what you were seeing, and what browser you're using? We were able to set your "Alpha" catalog as primary in your problem by clicking that option, no problem.

10 |1200

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

Nate McDorman avatar image
Nate McDorman answered

Hi Brendan, I took a screenshot of what I currently see (I purposefully distorted the card id's since this is a public post). The star for "Primary Catalog" was simply not filled before and clicking it did not create any kind of reaction. I am using Google Chrome. I can see it filled now that you have done so on your end. Thank you!

10 |1200

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

brendan avatar image
brendan answered

That's odd - we're also using Chrome, and we were able to set your catalog by clicking on the option, as expected. If you see this again (when you have a second catalog), please do let us know, so that we can try to debug with you.

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.