question

Travis Lange avatar image
Travis Lange asked

Server Get Contact Email Addresses

We are attempting to get the ContactEmail addresses with this code in CloudScript. We ultimately just want to return a boolean that states whether or not the email address is validated. Currently, we can't see the contact email addresses even though we are on the server. (We are just returning the entire profile now for testing).

handlers.travisScript = function () {
  	var playerData = server.GetPlayerProfile({"PlayFabId" : currentPlayerId}, {"ShowAvatarUrl":false,"ShowBannedUntil":false,"ShowCampaignAttributions":false,"ShowContactEmailAddresses":false,"ShowCreated":false,"ShowDisplayName":false,"ShowLastLogin":false,"ShowLinkedAccounts":false,"ShowLocations":false,"ShowMemberships":false,"ShowOrigination":false,"ShowPushNotificationRegistrations":false,"ShowStatistics":false,"ShowTags":false,"ShowTotalValueToDateInUsd":false,"ShowValuesToDate":false});
    
  return { messageValue: playerData };
}
CloudScript
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.

Travis Lange avatar image Travis Lange commented ·

There is a typo in the code . Idk why but I can't seem to edit it after posting. Anyways, the function should look like this:

handlers.travisScript = function () {  	var playerData = server.GetPlayerProfile({"PlayFabId" : currentPlayerId}, {"ShowAvatarUrl":false,"ShowBannedUntil":false,"ShowCampaignAttributions":false,"ShowContactEmailAddresses":true,"ShowCreated":false,"ShowDisplayName":false,"ShowLastLogin":false,"ShowLinkedAccounts":false,"ShowLocations":false,"ShowMemberships":false,"ShowOrigination":false,"ShowPushNotificationRegistrations":false,"ShowStatistics":false,"ShowTags":false,"ShowTotalValueToDateInUsd":false,"ShowValuesToDate":false});      return { messageValue: playerData };}

But we still can't get ContactEmailAdresses, even when "ShowContactEmailAdresses" is true on server side.

0 Likes 0 ·
Travis Lange avatar image Travis Lange commented ·

Sorry for the below code being badly formatted. The text editor rearranged it after I posted and I can't revise it.

0 Likes 0 ·
Travis Lange avatar image
Travis Lange answered

I ended up fixing it. It turns out you have to declare that you are setting the variable "ProfileConstraints". Here is the working code:

// Gets the EmailVerificationStatus for this player.
handlers.getEmailVerificationStatus = function () {
  	var playerData = server.GetPlayerProfile({"PlayFabId" : currentPlayerId,"ProfileConstraints" : { "ShowContactEmailAddresses": true }});
  	var contactEmailAdresses = playerData.PlayerProfile.ContactEmailAddresses;
  	var emailVerificationStatus = null;
  	if (contactEmailAdresses != null && contactEmailAdresses.length > 0) {
      	emailVerificationStatus = contactEmailAdresses[0].VerificationStatus;
    }
  
    return { emailVerificationStatus: emailVerificationStatus };
}
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

It seems you didn’t use ProfileConstraints properly, please see the code below:

handlers.travisScript = function (){
	var playerData = server.GetPlayerProfile( 
		{ 
			"PlayFabId": currentPlayerId, 
			"ProfileConstraints":
			{"ShowAvatarUrl":false,"ShowDisplayName":true //any other constraints....
			}
		}
	);
	return { messageValue: playerData };
}

The thing is you have to input ProfileConstraints as a key in the request, with the constraints as its value lists.

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.