question

Kim Strasser avatar image
Kim Strasser asked

How can I get the SessionTicket creation date in Cloud Script?

I get the following response if I use Server/AuthenticateSessionTicket in Postman:

{
    "code": 200,
    "status": "OK",
    "data": {
        "UserInfo": {
            "PlayFabId": "8882308D85826F31",
            "Created": "2019-12-22T08:22:30.749Z",
            "Username": "postmanuser",
            "TitleInfo": {
                "DisplayName": "PostmanDisplayname",
                "Origination": "Organic",
                "Created": "2019-12-22T08:22:30.937Z",
                "LastLogin": "2019-12-25T18:54:49.545Z",
                "FirstLogin": "2019-12-22T08:22:30.937Z",
                "isBanned": false,
                "TitlePlayerAccount": {
                    "Id": "7BBDEEBC993F528B",
                    "Type": "title_player_account",
                    "TypeString": "title_player_account"
                }
            },
            "PrivateInfo": {
                "Email": "postmanemail@test.com"
            }
        }
    }
}

But I can not find the creation date of the SessionTicket. What is the creation date in this example? Is it data.UserInfo.Created?

And in my cloud script I get an exception if I want to get data.UserInfo.Created.

"Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "TypeError: Cannot read property 'UserInfo' of undefined\n    at handlers.GetSessionTicketCreationDate (BFD0A-main.js:600:49)\n    at Object.invokeFunction (Script:116:33)"
        }
handlers.GetSessionTicketCreationDate = function (args, context)
{
    var result = server.AuthenticateSessionTicket(
    {
        SessionTicket: args.Sessionticket
    });
       
    var sessionticketcreationdate = "";
    if (result.Error == null)
    {
        sessionticketcreationdate = result.data.UserInfo.Created;
    }
    else
        sessionticketcreationdate = "Could not get SessionTicket creation date."

    return sessionticketcreationdate;
}

How can I get the SessionTicket creation date in Cloud Script?

CloudScript
10 |1200

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

Turner avatar image
Turner answered

Hey Kim,
UserInfo.Created is just the timestamp for when the User account was created. In order to get your desired result, you'll have to use PlayerData. You'll have to create your own timestamps and do something like UpdateUserData when they log in to store the timestamps, And when you want to evaluate the timestamps you would just call GetUserData to retrieve timestamp.

10 |1200

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

Seth Du avatar image
Seth Du answered

Sorry for any confusion in previous threads, It seems to be like what Turner have mentioned, you need to create your own timestamp

I highly recommend you to use Restful API testing tools like Postman to test PlayFab API. I have called AuthenticateSessionTicket to get a sample response for your refrerence:

{
    "code": 200,
    "status": "OK",
    "data": {
        "UserInfo": {
            "PlayFabId": "8A364330FCxxxxxxx",
            "Created": "2019-03-28T02:05:29.912Z",
            "TitleInfo": {
                "Origination": "CustomId",
                "Created": "2019-10-01T04:25:31.371Z",
                "LastLogin": "2019-12-26T01:41:31.284Z",
                "FirstLogin": "2019-10-01T04:25:31.371Z",
                "isBanned": false,
                "TitlePlayerAccount": {
                    "Id": "89C409CAxxxxxxxx",
                    "Type": "title_player_account",
                    "TypeString": "title_player_account"
                }
            },
            "PrivateInfo": {
                "Email": "asd@avc.com"
            },
            "CustomIdInfo": {
                "CustomId": "67AB-5397-CCxxxxxxx"
            }
        }
    }
}

I believe the LastLogin property can be useful for you.

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.

Kim Strasser avatar image Kim Strasser commented ·

Why am I getting a JavascriptException in this Cloud Script code?

result.data.UserInfo.Created;

In Postman, it has the same structure(data-->UserInfo-->Created) and I thought that I can use the same structure in my Cloud Script than in the Postman response:

"data": {
        "UserInfo": {
            "PlayFabId": "8A364330FCxxxxxxx",
            "Created": "2019-03-28T02:05:29.912Z",
...
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.