question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

Cannot change API policy

Hello everyone,

I was trying to update my API policy, but I get this error.

0 is not allowed as a policy version. Make sure to merge PolicyVersion and Statements returned by GetPolicy with this request.

I was able to update the policy yesterday, now it gives me that error. This is the code I use:

        static void Main(string[] args)
        {
            // ... Adjusting static settings here. Title ID and Secret Key


            WritePolicy();
            GetPolicy();
        }

        static void WritePolicy()
        {
            Console.WriteLine("Writing a New API Policy...\n");

            UpdatePolicyRequest updatePolicy = new UpdatePolicyRequest()
            {
                OverwritePolicy = true,
                PolicyName = "ApiPolicy",
                Statements = new List<PermissionStatement>()
                {
                    new PermissionStatement()
                    {
                        Action = "*",
                        ApiConditions = new ApiCondition() {
                            HasSignatureOrEncryption = Conditionals.False
                        },
                        Comment = "test",
                        Resource = "pfrn:api--/Client/LoginWithPlayFab",
                        Effect = EffectType.Allow,
                        Principal = "*"
                    },
                }
            };

            Task<PlayFabResult<UpdatePolicyResponse>> policyResult = PlayFabAdminAPI.UpdatePolicyAsync(updatePolicy);

            while (!policyResult.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            //Console.WriteLine(policyResult.Result.Error.ErrorMessage);
        }

        static void GetPolicy()
        {
            Console.WriteLine("Getting API Policy...\n");

            GetPolicyRequest getPolicy = new GetPolicyRequest()
            {
                PolicyName = "ApiPolicy"
            };

            Task<PlayFabResult<GetPolicyResponse>> policyResult = PlayFabAdminAPI.GetPolicyAsync(getPolicy);

            while (!policyResult.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            foreach (var item in policyResult.Result.Result.Statements)
            {
                Console.WriteLine("Action: " + item.Action);
                Console.WriteLine("Comment: " + item.Comment);
                if (item.ApiConditions != null)
                {
                    Console.WriteLine("ApiCondition.HashSignatureOrEncryption: " + item.ApiConditions.HasSignatureOrEncryption);
                }
                Console.WriteLine("Effect: " + item.Effect);
                Console.WriteLine("Principal: " + item.Principal);
                Console.WriteLine("Resource: " + item.Resource);
                Console.WriteLine("");
            }

            Console.ReadKey();
        }

I'm trying to change the API policy of my test game, which is in this account. Title ID: AFE9A

10 |1200

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

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

It seems that PlayFab added the “PolicyVersion” property for API UpdatePolicy and GetPolicy. And the C# SDK hasn’t followed up. If you need to use this API immediately, you can modify the C# SDK to fix this issue. To modify the C# source code, you need to download the project from our official GitHub repo -- CSharpSDK/PlayFabSDK at master. Then you can add the “public int PolicyVersion;” to PlayFab.AdminModels.GetPolicyResponse class and PlayFab.AdminModels.UpdatePolicyRequest class. In addition, as the error message said, you need to call the GetPolicy API first, get the current PolicyVersion, then pass it in the request of UpdatePolicy.

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

Ozan Yilmaz avatar image Ozan Yilmaz commented ·

@Sarah Zhang

The problem about that solution is I cannot add required defines in the project that can be seen by every source code. I cannot access Admin nor Server API if I add them manually.

Is there a way to define ENABLE_PLAYFABSERVER_API and ENABLE_PLAYFABADMIN_API defines somewhere in the project to activate those APIs?

(I'm using a C# Console Application)

0 Likes 0 ·
Ozan Yilmaz avatar image Ozan Yilmaz commented ·

Nevermind, I added the related defines to the project's properties. It's working now.

0 Likes 0 ·

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.