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