question

Kim Strasser avatar image
Kim Strasser asked

CloudScript: User already linked to a different account

I get this error message when I want to use the POST method for AddUsernamePassword in my cloud script:

"FunctionResult": {
      "code": 400,
      "status": "BadRequest",
      "error": "AccountAlreadyLinked",
      "errorCode": 1011,
      "errorMessage": "User already linked to a different account"
    }
function AddUsernamePasswordFromCloudScript(sessionticket, email, username, password, playFabId)
{
    var contentBodyTemp = {
        "PlayFabId": playFabId,
        "Email": email,
        "Username": username,
        "Password": password
    };
    
    let url = "https://E5E2C.playfabapi.com/Client/AddUsernamePassword";
    let method = "POST";
    let contentBody = `{"PlayFabId": "${playFabId}", "Email": "${email}", "Username": "${username}", "Password": "${password}"}`;
    let contentType = "application/json";
    let headers = { "X-Authentication": sessionticket };
    let responseString = http.request(url, method, contentBody, contentType, headers);
    let responseJSONObj = JSON.parse(responseString);
    return (responseJSONObj);
    
    if (responseJSONObj.Error == null)
        return "true";
    else
    {
        log.info("Error code: " + responseJSONObj.error.toString());
        // return error code to client.
        return responseJSONObj.error;
    }
}

At the beginning, I use PlayFabClientAPI.LoginWithAndroidDeviceID with CreateAccount = true to create a new account when a player starts my game the very first time. Later, the player needs to add email, username and password and therefore I use the POST method in my cloud script. In addition, the player should have the possibility to change email, username and password on a later date if he wants. But I always get this error message when the player wants to change his email, username and password. I have already tried to unlink and link the device again in the client code but it still doesn't work. I always get the error message "User already linked to a different account".

Can I use the POST method for AddUsernamePassword only once when the new account is created? Is it not possible to use it again when the player wants to change his email, username and password?

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.

1 Answer

·
Seth Du avatar image
Seth Du answered

The AddUsernamePassword API adds the username, email and password for the master account of a player. I’m afraid that the username and email of the master account are not meant to be changed. It is explained in this thread.

About changing password in Client side, you may follow this document Using email templates to send an account recovery email to set up Account recovery for player. After set up, the steps to change password would be:

  1. Player call SendAccountRecoveryEmail API in client side.
  2. Player receives email and click the link and go to your website.
  3. Player enters password and submit, your website then calls the Admin API ResetPassword to reset the password for player.

In the common scenario, we won't recommend sending HTTP request on Cloud Script and you may take care of the response time due to the runtime limit of Cloud Script. I also don't see any additional part of verification steps before this API is called. You may simply implement AddUsernamePassword API on the client side.

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.

Kim Strasser avatar image Kim Strasser commented ·

Is it possible to only find out if a username or email address already exists when I use AddUsernamePassword or another API call? I want to display a message in my game if the desired username or email(the player needs to enter it in a text box) can be used to create a new account.

For example, if the username/email is available then the player has the possibility to click on a registration button to complete the registration or he can enter another username/email in the text box. If the desired username/email is not available because it is already used by another player, then display an error message in my game so that the player knows that he needs to enter another username/email.

The problem is that AddUsernamePassword automatically adds the username/email if it is not used by another player. Is it possible to only check if the desired username and email is available without adding them automatically to the players account?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

: I suggest using this client API GetAccountInfo. This API allows you to find an account by either Email, Username or other id. You can use this API to check if the username or email is available.

When call GetAccountInfo API:

  • If an account is found, it will return data about the Account. At this point we know the username or email is not available, then you can prompt the user to try another username or email.
  • If no account is found, it will return error “AccountNotFound”, which means the username or email is available.
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.