Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get Value from odata json in C#

(0) ShareShare
ReportReport
Posted on by 250

Hello everyone my name is Taniguchi and i am using web api to connect to dynamics 365, and i was able to  retrive entities records but my variable is bringing all the collums on my select. but i want to take a specificied collum like contact full.

how could i do that ?

this is my code so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net.Http.Headers;
using System.Net.Http;
using Newtonsoft.Json.Linq;

namespace WebApi
{
class Program
{
static void Main(string[] args)
{
var Username = ConfigurationManager.AppSettings["Username"];
var Password = ConfigurationManager.AppSettings["Password"];
var ServerAddress = ConfigurationManager.AppSettings["ServerAddress"];
var RedirectUrl = ConfigurationManager.AppSettings["RedirectUrl"];
var ClientId = ConfigurationManager.AppSettings["ClientId"];
string redirectUrl = "ax4bdev.api.crm2.dynamics.com/.../v9.1";
string Nome_Usuario;
Console.Write("Enter Username - ");
Nome_Usuario = Console.ReadLine();

string senha;
Console.Write("Enter Passord - ");
senha = Console.ReadLine();


AuthenticationContext authContext = new AuthenticationContext("login.windows.net/common", false);
UserCredential cred = new UserCredential(Nome_Usuario, senha);
AuthenticationResult result = authContext.AcquireToken(RedirectUrl, ClientId, cred);

HttpClient httpClient = null;
httpClient = new HttpClient();
//Default Request Headers needed to be added in the HttpClient Object
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

//Set the Authorization header with the Access Token received specifying the Credentials
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);

httpClient.BaseAddress = new Uri(redirectUrl);
var response = httpClient.GetAsync("contacts?$select=fullname&$filter=emailaddress1 eq '" + Nome_Usuario + "'").Result;
string queryOptions = "contacts?$select=fullname&$filter=emailaddress1 eq '" + Nome_Usuario + "'";
//if (response.IsSuccessStatusCode)

if (response.IsSuccessStatusCode)
{

var retrievedcontact1 = response.Content.ReadAsStringAsync().Result;
dynamic data = JObject.Parse(retrievedcontact1);
string employeeName = (string)data["contactid"];
Console.WriteLine(data);
Console.ReadKey();
}

}
}
}

*This post is locked for comments

  • Suggested answer
    PranavShroti Profile Picture
    PranavShroti 4,510 on at
    RE: Get Value from odata json in C#

    Hello,

    Try the schema name "FullName" not the logical name "fullname"

    and try $select=FullName, CreatedOn,

    Hope this helps,

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans