1

I want to use xconnect to download pattern cards. The contact has pattern cards (I checked in his profile). I extended contact download with ContactBehaviorProfile. Below is my code

IReadOnlyCollection<IEntityLookupResult<Contact>> contacts = client.Get<Contact>(references, new ContactExpandOptions(emailsFacetKey, personalFacetKey, contactBehaviorProfileFacetKey)
{
});

if (contacts != null && contacts.Any())
{
    var c = contacts.First();
    // For each contact, retrieve the facet - will return null if contact does not have this facet set
    EmailAddressList emailsFacetData = c.Entity.GetFacet<EmailAddressList>(emailsFacetKey);
    PersonalInformation personalFacetData = c.Entity.GetFacet<PersonalInformation>(personalFacetKey);
    ContactBehaviorProfile contactBehaviorProfileData = c.Entity.GetFacet<ContactBehaviorProfile>(contactBehaviorProfileFacetKey);
    res.Contact.ID = id;
    if (emailsFacetData != null)
    {
        // Do something with data - e.g. display in view
        EmailAddress preferred = emailsFacetData.PreferredEmail;
        res.Contact.Email = preferred.SmtpAddress;
    }
    if (personalFacetData != null)
    {
        res.Contact.FirstName = personalFacetData.FirstName;
        res.Contact.LastName = personalFacetData.LastName;
    }
    res.Contact.Patterns = new List<Tuple<double, Guid?>>();
    if (contactBehaviorProfileData != null)
    {
        foreach (var score in contactBehaviorProfileData.Scores)
        {
            var value = score.Value;
            res.Contact.Patterns.Add(new Tuple<double, Guid?>(value.Score, value.MatchedPatternId));
            res.Contact.Patterns.Add(new Tuple<double, Guid?>(value.ScoreCount, value.ProfileDefinitionId));
        }
    }
}

Unfortunately, the values returned in the list are empty:

   "Contact":{
      "ID":"123",
      "FirstName":"Jan",
      "LastName":"Nowak",
      "Email":"test@test.pl",
      "Patterns":[
         {
            "Item1":0.0,
            "Item2":null
         },
         {
            "Item1":0.0,
            "Item2":null
         }
      ]
   }

I checked in mongo and the right facet have:

{
    "_id" : {
        "id" : UUID("e1eaf15b-6d79-4379-8b28-db7fa805eaff"),
        "parent_id" : UUID("e1eaf15b-6d79-4379-8b28-db7fa805eaff"),
        "f_key" : "ContactBehaviorProfile"
    },
    "ct" : UUID("b8c050f7-7343-48ec-9695-67b976164e4b"),
    "lm" : NumberLong(637604704272065180),
    "content" : {
        "Scores" : [ 
            {
                "Key" : "24dff2cf-b30a-4b75-8967-2fe3ded82271",
                "Value" : {
                    "ProfileDefinitionId" : "24dff2cf-b30a-4b75-8967-2fe3ded82271",
                    "Values" : [ 
                        {
                            "Key" : "b32bfacc-3494-4127-b050-cf50078e2b4c",
                            "Value" : 5.0
                        }, 
                        {
                            "Key" : "f5652c06-676b-4e12-a9d0-06d000e5f1c8",
                            "Value" : 10.0
                        }
                    ]
                }
            }, 
            {
                "Key" : "33a8bd77-1495-4bb7-8802-cca8ce7acb5b",
                "Value" : {
                    "ProfileDefinitionId" : "33a8bd77-1495-4bb7-8802-cca8ce7acb5b",
                    "Values" : [ 
                        {
                            "Key" : "4dd4ac01-0b76-4a13-a7e3-4137faccd6ea",
                            "Value" : 30.0
                        }, 
                        {
                            "Key" : "1629166e-8f7d-4d6d-94af-250f93922a18",
                            "Value" : 5.0
                        }
                    ]
                }
            }
        ],
        "SourceInteractionStartDateTime" : "2021-06-28T09:47:07.1835232Z",
        "_odata_type" : "#Sitecore.XConnect.Collection.Model.ContactBehaviorProfile"
    }
}

Anyone have any idea what I'm doing wrong? I need to download a pattern card for a contact. Basically the information that is displayed in xProfile.

Edit: Alternatively, does anyone know how to call the library from the Sitecore: http:///sitecore/api/ao/v1/contacts/e067229b-cd02-0000-0000-0629a29daa77/intel/profile-pattern-matches/33a8bd77-1495-4bb7-8802-cca8ce7acb5b/?&pageSize=10&pageNumber=1&visitId=e1dc01bd-801a-0000-0000-062b67b7c466&sort=PatternGravityShare%20desc

3
  • Is contactBehaviorProfileData ever not null?
    – Chris Auer
    Jun 29 at 19:05
  • 1
    And you should know that profile scores are also kept in the InteractionsCache facet in the property InteractionsCache.ProfileScores[]. And there is no guarantee that the ContactBehaviorProfile and InteractionsCache match. But InteractionsCache is what you see in XP.
    – Chris Auer
    Jun 29 at 19:08
  • InteractionsCache - I didn't know that. But in xProfile I have pattern assigned, but again in InteractionsCache the collections are empty.
    – Jan Nowak
    Jun 30 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.