question

joerg-miethe avatar image
joerg-miethe asked

how to acsses an entity with javascript

Hello Everyone :-)

i've tried to create an entity from client with javascript with SDK, but always get the following error:

Object

  1. CallBackTimeMS: 1506
  2. CustomData: undefined
  3. Request: {Entity: {Id: "560DEDF4B935625D", Type: "title_player_account"}, Objects: {...}}
  4. code: 400
  5. error: "InvalidParams"
  6. errorCode: 1000
  7. errorDetails: {"The Entity field is required.", "The Objects field is required."}
  8. errorMessage: "Invalid input parameters"
  9. status: "BadRequest"

I'm quite sure I got the correct ID and Type from EntityToken but something musn't be right in my request :-(

Any idea where to look for a working Json Sample?

Thanx You verry much

Jörg

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

joerg-miethe avatar image joerg-miethe commented ·

sorry...

I thinck should have given more detailed information...

I used the setObjects() function from the data SDK and the my title is 36FDD

Want to create a entity data object for each player title...

best regards

jörg miethe

0 Likes 0 ·
Sarah Zhang avatar image
Sarah Zhang answered

The reason causes this error is that you haven’t passed the corresponding EntityToken as the request header when you call the API SetObjects. PlayFabSDK would help you store the EntityToken to the PlayFabSettings programmatically. So you just need to call this API SetObjects in the call back function of some login API to let the request header contains the correct EntityToken. You can refer to the following testing code.

function DoExampleLoginWithCustomID() {
    PlayFab.settings.titleId = document.getElementById("titleId").value;
    var loginRequest = {
        TitleId: PlayFab.settings.titleId,
        CustomId: document.getElementById("customId").value,
        CreateAccount: true
    };

    PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback);
}

var LoginCallback = function (result, error) {
    if (result !== null) {
        document.getElementById("resultOutput").innerHTML = JSON.stringify(result);
        var setObjectRequest = {
            Entity: {
                Id: result.data.EntityToken.Entity.Id,
                Type: result.data.EntityToken.Entity.Type
            },
            Objects: [...]
        };
        PlayFabDataSDK.SetObjects(setObjectRequest, SetObjectsCallback);

    } else if (error !== null) {
        document.getElementById("resultOutput").innerHTML = PlayFab.GenerateErrorReport(error);
    }
}
var SetObjectsCallback = function (result, error) {
    if (result !== null) {
        document.getElementById("resultOutput").innerHTML = JSON.stringify(result);
    } else if (error !== null) {
        document.getElementById("resultOutput").innerHTML = PlayFab.GenerateErrorReport(error);
    }
}

10 |1200

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

joerg-miethe avatar image
joerg-miethe answered

Thanx al again :-)

You made sure my Key was right so I concentrated on the Objects ... and my Object didn't had a name :-(

var setObjectRequest = { Entity: { Id: TitlePlayerID, Type: TitlePlayerType, },

Objects: [{ 'ObjectName': 'MyFarm',

'DataObject': { }

} }], };

Now it works for One Object .... if I send more ... its sasy Key ObjectName already in use ...

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.