web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Getting empty fields from CRM using Web API

(0) ShareShare
ReportReport
Posted on by 57

Hello

I have issues getting data out of CRM using Web API, my examples here are focused on the accounts entity:

Case 1: While extracting the accounts list the field 'accountnumber' comes empty for cases having values in CRM

{ "name": "DWAccountsQuery", "description": "DW query for entity account", "querytype": 0, "returnedtypecode": "account", "fetchxml": "<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>
<entity name ='account'><attribute name ='accountid' /><attribute name ='accountnumber' /><attribute name ='name' /><attribute name ='statuscode' /><order attribute='accountid' /></entity></fetch>"}

request.Content = new StringContent(userQueryRep, Encoding.UTF8, "application/json");
response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;

no error is reported in the communication, accountid always come with value.

Case2: While knowing an specific accountid, the following query returns empty value for 'accountnumber'
accounts(b1163787-88aa-e711-8109-c4346bdc92c1)?$select=accountid,accountnumber
response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;

no error is reported in the communication, accountnumber comes empty.

Thank you in advance for your help.

I have the same question (0)
  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Getting empty fields from CRM using Web API

    Hi Partner,

    Please check the following points.

    1.Test the web api through web url directly to check if the response contains accountnumber.

    Specific account.

    2465.pastedimage1601015326214v1.png

    Multiple account.

    1263.pastedimage1601015381352v2.png

    2.Debug your code in VS step by step to make sure if the original response is null or caused by the coding(UTF-8).

    You could also share your complete code about the query function so that we could debug for you.

    Regards,

    Leo

  • Enediel Gonzalez Profile Picture
    57 on at
    RE: Getting empty fields from CRM using Web API

    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)
    {

    }
    }

  • Enediel Gonzalez Profile Picture
    57 on at
    RE: Getting empty fields from CRM using Web API

    with the previous code, while debugging the application I got accountnumber=null while accountid and "name" had valid values.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Getting empty fields from CRM using Web API

    Hi,

    Strange!

    Make sure you have not enabled Field Security Profile for account number field in Dynamics CRM.

    Also, The data for Account Number does exist in Dynamics.

    crmbook.powerobjects.com/.../

    Please mark my answer verified if i were helpful

  • Suggested answer
    Pankaj Gogoi Profile Picture
    3,177 on at
    RE: Getting empty fields from CRM using Web API

    Hi,

    Can you do an advance find on Account where accountnumber not equal to null or use the below url and  see if you get any data.

    https://yourcrm/api/data/v9.1/accounts?$filter=accountnumber ne null

    Best Regards,

    PG

  • Suggested answer
    Enediel Gonzalez Profile Picture
    57 on at
    RE: Getting empty fields from CRM using Web API

    Thank everyone of you who helped me on this issue, deeply appreciated. The company was using jov_accountid instead of accountnumber, kind of confusing.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 72 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 58

#3
Martin Dráb Profile Picture

Martin Dráb 54 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans