question

matt-5 avatar image
matt-5 asked

How to call SetObjects to create an object with the correct entity type

I'd like to write a character object via SetObjects, but apparently it's trying to write entity type "title_player_account" rather than "character". I'm writing this code in a Windows Forms app and I'm using JSON.NET as my serializer.

Here are the steps as I understand them:

  1. Login via PlayFabClientAPI.LoginWithCustomIDAsync
  2. Get a "character" token via PlayFabEntityAPI.GetEntityTokenAsync
  3. Save the object via PlayFabEntityAPI.SetObjectsAsync

However the token I receive from GetEntityTokenAsync in step 2 is apparently for objects of type "title_player_account". How should I request a character token instead?

Here's my code to get the character token:

And here's my code to write the object via SetObjectsAsync:

apisCharacter DataCharacters
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

·
pfnathan avatar image
pfnathan answered

You would need additional steps, please take a look: https://api.playfab.com/documentation/entity/method/GetEntityToken

An optional EntityKey may be included to attempt to set the resulting EntityToken to a specific entity, however, the entity must be a relation of the caller, such as the master_player_account of a character. So, you need to get the character ID then call GetEntityToken with “EntityType="character", EntityId = "thecharacterid" as an argument, and since you are putting the “Type” in Character which is fine but it will missing the ID too so you need them on both.

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.

matt-5 avatar image matt-5 commented ·

OK, to confirm, I can't use SetObjects to create an object. Instead, the flow should be:

  1. Use the client API "UpdateCharacterData" to create the object
  2. Use GetEntityToken as you describe to retrieve a token for the object
  3. Further updates to the object can use SetObjects as needed

However UpdateCharacterData takes a Dictionary representing the object and I'd like to store an arbitrary JSON object. So presumably I'd create an empty object, retrieve the token and use SetObjects to set the JSON?

Thanks!

0 Likes 0 ·
pfnathan avatar image pfnathan ♦ matt-5 commented ·

To reiterate on the first response., they are Entity.ID and Entity.Type. So the ID is required element for both in the call.

Getting a character's entity token does all the background tasks to set up a character entity to accept objects. It does not UpdateCharacterData to create a character, so, assuming that you have all character in the first place; (you need to create a character first ofcourse)

client method: https://api.playfab.com/documentation/client/method/GrantCharacterToUser

server method: https://api.playfab.com/documentation/server/method/GrantCharacterToUser

So, once you have created a character with those, the CharacterId returned from those methods is the ID you want to use GetEntityToken with.

As for an example, assuming the ID returned is "1234567" he needs to call GetEntityToken with Entity = {Type = "character", Id = "1234567"}

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.