question

Ittipon Teerapruettikulchai avatar image
Ittipon Teerapruettikulchai asked

PlayFabEconomyAPI.ExecuteInventoryOperation alwas response "NotAuthorizedByTitle"

I am going to add multiple items to player's inventory, by PlayFabEconomyAPI.ExecuteInventoryOperation but it is always response "NotAuthorizedByTitle", not sure what is wrong with it, here is my codes:

[System.Serializable]
        public struct Reward
        {
            public string itemFriendlyName;
            public int itemAmount;
        }


        private void ExecuteInventoryOperations(UserAccountInfo accountInfo)
        {
            var ops = new List<InventoryOperation>();
            for (int i = 0; i < rewards.Length; ++i)
            {
                ops.Add(new InventoryOperation()
                {
                    Add = new AddInventoryItemsOperation()
                    {
                        Item = new InventoryItemReference()
                        {
                            AlternateId = new AlternateId()
                            {
                                Type = "FriendlyId",
                                Value = rewards[i].itemFriendlyName,
                            }
                        },
                        Amount = rewards[i].itemAmount,
                    },
                });
            }
            PlayFabEconomyAPI.ExecuteInventoryOperations(new ExecuteInventoryOperationsRequest()
            {
                Operations = ops,
                Entity = new EcoEntityKey
                {
                    Id = accountInfo.TitleInfo.TitlePlayerAccount.Id,
                    Type = accountInfo.TitleInfo.TitlePlayerAccount.Type
                }
            }, response =>
            {
                if (particlesPrefab != null)
                {
                    GameObject particles = Instantiate(particlesPrefab, PlayerEntity.Mine.transform.position, Quaternion.identity);
                    Destroy(particles, particleEffectDuration);
                }
            }, error =>
            {
                Debug.LogError(error.Error);
                AppInstance.Instance.ShowErrorMessageDialog(LanguageManager.GetText(error.ErrorMessage));
            });
        }

But it is fine for PlayFabEconomyAPI.AddInventoryItems with similar parameters (enity, item alternate id) so I have to use it for now.

In-Game EconomyPlayer Inventory
10 |1200

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

kylemc@microsoft.com avatar image
kylemc@microsoft.com answered

Oh. I didn't realize that checkbox was disabled for ExecuteInventoryOperations. I think that's a bug. Let me investigate to figure out what's going on.

10 |1200

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

Infer Wang avatar image
Infer Wang answered

You can follow GameManager->Title settings->Economy(V2)->Policy(V2), then find the ExecuteInventoryOperations. 6475-image.png As the picture shows, you need two kinds of permission. However, this cannot be checked. So, you may update policy. You can follow these steps: First, call GetPolicy and copy all statements and "PolicyVersion". Then, call UpdatePolicy, this is the request body:

 {
   "PolicyName": "ApiPolicy",
   "Statements": [
    
   ],
   "OverwritePolicy": true,
   "PolicyVersion": 8
 }

Paste the statements you copied from GetPolicy’s result. Find the ExecuteInventoryOperations and change “Effect” to Allow. And make sure "PolicyVersion” is same as the one in GetPolicy’s result.


image.png (25.8 KiB)
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.