In order to fetch the User
by email, you will need to run two queries as below.
- Search for the email property on the
UserProfile
entity definition with the query as below.
/api/entities/query?query=Definition.Name=='M.UserProfile' AND String('Email')=='{Email_Address}'
Since email property exist on M.UserProfile
entity, hence we first need to get the user profile.
- Once the user profile is retrieved, we can fetch the
User
by readingUserToUserProfile
relation in the above api response.
This relation contains the User
associated with the user profile. Using this way we can fetch the user details using email in Content Hub.
Moreover, in case you are using Web SDK
, you can use following snippet to fetch user by email.
using Stylelabs.M.Base.Querying;
using Stylelabs.M.Base.Querying.Linq;
using Stylelabs.M.Framework.Essentials.LoadConfigurations;
using Stylelabs.M.Sdk.Contracts.Base;
using Stylelabs.M.Sdk.WebClient;
using Stylelabs.M.Sdk.WebClient.Authentication;
using System;
using System.Linq;
using System.Threading.Tasks;
string email = "{{EmailAddress}}";
var query = Query.CreateQuery(entities =>
from e in entities
where e.DefinitionName == "M.UserProfile"
&& e.Property("Email") == email
select e);
var queryResult = await MClient.Querying.SingleAsync(query, EntityLoadConfiguration.Full);
var userProfileRelation = await queryResult.GetRelationAsync<IChildToOneParentRelation>("UserToUserProfile");
if (userProfileRelation != null)
{
var userProfileId = userProfileRelation.GetId();
var user = await MClient.Entities.GetAsync(userProfileId.Value, EntityLoadConfiguration.Full);
}
Hope this helps!!!