Thank you for your answer
Let's limit the question to one, having the accountid from CRM, how to get data that currently is coming out empty like accountnumber.
Global variables and functions
-----------
protected HttpClient client = null;
JObject collection;
public static HttpClient Client_GetHttpClient(string connectionString, string clientId, string redirectUrl, string version)
{
string url = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Url");
string username = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Username");
string domain = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Domain");
string password = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Password");
string authType = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "authtype");
try
{
HttpMessageHandler messageHandler;
switch (authType)
{
case "Office365":
case "IFD":
messageHandler = new OAuthMessageHandler(url, clientId, redirectUrl, username, password,
new HttpClientHandler());
break;
case "AD":
NetworkCredential credentials = new NetworkCredential(username, password, domain);
messageHandler = new HttpClientHandler() { Credentials = credentials };
break;
default:
throw new ArgumentOutOfRangeException("Valid authType values are 'Office365', 'IFD', or 'AD'.");
}
HttpClient httpClient = new HttpClient(messageHandler)
{
BaseAddress = new Uri(string.Format("{0}/api/data/{1}/", url, version)),
Timeout = new TimeSpan(0, 2, 0) //2 minutes
};
return httpClient;
}
catch (Exception)
{
throw;
}
}
-----------
From CRM I was able to extract the name and accountid for all the accounts, in the following code I need to extract the accountnumber for the accountid b1163787-93aa-e711-8109-c4346bdc92c1, right now is coming out empty when accountid and "name" come out with their proper values.
string[] AccountEntityAdditionalProperties = {
"accountid"
,"accountnumber"
,"name"
};
client = Client_GetHttpClient(
APICRMConnectionString,
AzureClientID,
AzureRedirectUrl,
"v9.1");
string url = "accounts(b1163787-93aa-e711-8109-c4346bdc92c1)?$select=accountid,accountnumber,name";
response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;
JObject collection;
if (!response.IsSuccessStatusCode)
return false;
collection = JObject.Parse(response.Content.ReadAsStringAsync().Result);
JArray singleton = new JArray(collection);
foreach (JObject entity in singleton)
{
string PropertyValue = "";
foreach (string PropertyName in AccountEntityAdditionalProperties)
{
try
{
string formattedProperty = PropertyName + "@OData.Community.Display.V1.FormattedValue";
PropertyValue = "";
if (null != entity[formattedProperty])
PropertyValue = entity[formattedProperty].ToString();
else
if (null != entity[PropertyName])
PropertyValue = entity[PropertyName].ToString();
}
catch (Exception ex)
{
}
}