question

Muhammad Hassan avatar image
Muhammad Hassan asked

Playfab Server API

I am trying to user GrantItemsToUser Server API to add items to player's inventory. The API works fine in the UNITY Editor but when I make a facebook WEB GL build from UNITY and call GrantItemsToUser it gives an error "/Server/GrantItemsToUser: Missing or invalid X-SecretKey HTTP header". Developer Secret Key is added in the PlayfabSharedSettings and I am using "CustomHTTP" as request type. What could be the issue?

apisunity3d
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Can you try using the secret key mentioned in the screenshot and make a same call via Postman? This helps identify whether there is something wrong with the secret key.

And, btw, did you check the "Enable Server API" option via EdEx? And, what's version of Unity, PlayFabUnityExtension & PlayFabUnitySDK?

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

Muhammad Hassan avatar image Muhammad Hassan commented ·

I have tried calling the API using POSTMAN and following this blog (https://api.playfab.com/blog/trying-out-playfab-services-using-postman). For login, Instead of LoginWithPlayfab I have used LoginWithFacebook. It returned successful with the session ticket. But with that session ticket and other parameters I was still getting the same error "Missing or invalid X-SecretKey HTTP header". I even tried to make another secret key but it didnt work with either of them.

0 Likes 0 ·
postman-error.png (94.6 KiB)
Citrus Yan avatar image Citrus Yan Muhammad Hassan commented ·

The name of the Key should be "X-SecretKey":

And, please enter one of the secret key(s) listed on this page for testing:

https://developer.playfab.com/en-US/r/t/your_title_id/settings/secret-keys

0 Likes 0 ·
x-sk.png (2.7 KiB)
Muhammad Hassan avatar image Muhammad Hassan Citrus Yan commented ·

Yes it works with the key "X-SecretKey" instead of "SecretKey". Its weird that the key name is not provided correctly in the documentation https://docs.microsoft.com/en-us/rest/api/playfab/server/player-item-management/grantitemstouser?view=playfab-rest

Now how do I make it work with Unity instead? Unity SDK might be doing the same. SDK version that I am using is "2.69.190625". EnableServerAPI check is true. Unity version is 2018.4.4f1

0 Likes 0 ·
Show more comments
Muhammad Hassan avatar image
Muhammad Hassan answered

Citrus, Yes I did. Its correct!

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.

Citrus Yan avatar image Citrus Yan commented ·

Could you please try updating the PlayFabUnityExtension & the PlayFabSDK to the latest version, re-configure the settings, and re-build the project?

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.