<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Sai Ede</title><link href="http://world.optimizely.com" /><updated>2019-05-28T12:52:15.0000000Z</updated><id>https://world.optimizely.com/blogs/sai-ede/</id> <generator uri="http://world.optimizely.com" version="2.0">Optimizely World</generator> <entry><title>Update/Get Insights DATA based on Profile ID.</title><link href="https://world.optimizely.com/blogs/sai-ede/dates/2019/5/updateget-insights-data/" /><id>&lt;p&gt;&lt;strong&gt;Episerver Insight&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;span&gt;is the&amp;nbsp;user interface for adding/updating visitor profile, you can add Custom User groups to Epi insights data to be able to personalize&amp;nbsp;the components on the website based on User Visitor roles in Epi. Below are the steps to Update the payload data in Epi Insights, Below are the pre-reqs that are needed to get started, Swagger URL and Profile Store key which we can get from Epi server.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Example of Swagger URL:-&amp;nbsp;&lt;a href=&quot;https://profilesapi-westus01.profilestore.episerver.net/swagger/&quot;&gt;https://profilesapi-westus01.profilestore.episerver.net/swagger/&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Profile Store Key:- Encoded Shared Key.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below is how we look at the data in swagger or postman and we can compare that to EpiInsights data,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src=&quot;/link/29f4067fef964ed3836ca1a682acfd0b.aspx&quot; width=&quot;500&quot; height=&quot;258&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src=&quot;/link/f6cb5ee47c8f49ffb8dcb2556b52f3d5.aspx&quot; width=&quot;500&quot; height=&quot;275&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src=&quot;/link/d7876139a1de436eabc54f0fbd954712.aspx&quot; width=&quot;500&quot; height=&quot;275&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a) Create Profile Class with the JSON object.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;img src=&quot;/link/ff86de676bf349e4984facd530247b2d.aspx&quot; width=&quot;500&quot; height=&quot;275&quot; /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Example of JSON object from Swagger&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public class ProfileData
{
public class Rootobject
{
public string ProfileId { get; set; }
public string Name { get; set; }
public string ProfileManager { get; set; }
public DateTime FirstSeen { get; set; }
public DateTime LastSeen { get; set; }
public int Score { get; set; }
public int Visits { get; set; }
public Info Info { get; set; }
public string[] ContactInformation { get; set; }
public string Scope { get; set; }
public Payload Payload { get; set; }
public string[] DeviceIds { get; set; }
}

public class Info
{
public string Picture { get; set; }
public string Website { get; set; }
public string StreetAddress { get; set; }
public string Phone { get; set; }
public string Mobile { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public string JobTitle { get; set; }
public string Company { get; set; }
public string Country { get; set; }
public string InferredCountry { get; set; }
public string Email { get; set; }
}

public class Payload
{
//Payload Custom Parameters
public string HomePhone { get; set; }
public string HomePhone2 { get; set; }
public string UserGroups { get; set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;b) Get the Insights Profile based on Name/Email or Profile ID Guid&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;String profileId = &quot;profile id from Epi&quot;;

String authSecurityKey = &quot;security key&quot;;
private String profileApi = &quot;profile API URL&quot;;
String scopeId = SiteDefinition.Current.Id.ToString().ToLowerInvariant();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(profileApi);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;epi-single&quot;, authSecurityKey);
var responseTask = client.GetAsync(String.Format(&quot;/api/v1.0/Profiles/{0}/{1}&quot;, scopeId, profileId));
responseTask.Wait();

var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{

using (HttpContent content = result.Content)
{

var readTask = result.Content.ReadAsAsync&amp;lt;ProfileData.Rootobject&amp;gt;();
readTask.Wait();
//getProfileData is the profile of an existing profile.
var getProfileData = readTask.Result;


}
}
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;c) Update Payload Data with Custom Objects.&amp;nbsp; Pass the profile data from step b to step c.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using (var client = new HttpClient())
{
//updating the payload data with custom parameters
getProfileData.Payload = new ProfileData.Payload { HomePhone = &quot;xxx-xxx-xxxx&quot;, HomePhone2 = &quot;xxx-xxx-xxxx&quot;, UserGroups = &quot;Add This Dynamically&quot; };
client.BaseAddress = new Uri(profileApi);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;epi-single&quot;, authSecurityKey);
//put method to insert the values into user profile.
var responseTask = client.PutAsJsonAsync(&quot;/api/v1.0/Profiles/&quot; + profileId, getProfileData);
var result = responseTask.Result;

}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;d) Get Tracking Info for Profile in Insights.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;img src=&quot;/link/e43978086dd34578b49cc6002ecc6aec.aspx&quot; width=&quot;500&quot; height=&quot;275&quot; /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public class TrackingData
{

public class Rootobject
{
public Item[] items { get; set; }
public int total { get; set; }
public int count { get; set; }
}

public class Item
{
public object TrackId { get; set; }
public string DeviceId { get; set; }
public string EventType { get; set; }
public DateTime EventTime { get; set; }
public string Value { get; set; }
public string Scope { get; set; }
public string CountryCode { get; set; }
public string PageUri { get; set; }
public object PageTitle { get; set; }
public string RemoteAddress { get; set; }
public Payload Payload { get; set; }
public User User { get; set; }
}

public class Payload
{
public string pageTypeName { get; set; }
public string pageTitle { get; set; }
public string domain { get; set; }
}

public class User
{
public string Name { get; set; }
public string Email { get; set; }
public Info Info { get; set; }
}

public class Info
{
public string company { get; set; }
public string website { get; set; }
public string phone { get; set; }
public string homePhone { get; set; }
}

StringBuilder sb = new StringBuilder();
String restMethod = &quot;/api/v1.0/trackevents/?$filter=ProfileId eq &quot; + profileId + &quot;&amp;amp;%24orderBy=EventTime%20DESC&quot;;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(profileApi);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;epi-single&quot;, authSecurityKey);
var responseTask = client.GetAsync(restMethod);
responseTask.Wait();

var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{
using (HttpContent content = result.Content)
{
var readTask = result.Content.ReadAsAsync&amp;lt;TrackingData.Rootobject&amp;gt;();
readTask.Wait();

var trackingDatas = readTask.Result;
foreach (var trackData in trackingDatas.items)
{
//Getting the track URL and track time from the track data as shown below
sb.AppendFormat(&quot;{0}:- Date {1}&quot;, trackData.PageUri, trackData.EventTime.ToString(&quot;MMMM dd, yyyy&quot;) + Environment.NewLine);
}
}
}
}

}&lt;/code&gt;&lt;/pre&gt;</id><updated>2019-05-28T12:52:15.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>