TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Preetham Holenarasipuradevera
NA
75
12.4k
Status 400 bad request for creating a record in crm dynamics 365
Feb 11 2021 11:47 PM
I am developing web application, that interact with crm dynamics 365, im facing the error while creating a record (post method) get method is working fine i am able to fetch the records from crm,
I am not sure its a correct community to ask here.
string resource = "https://*****.crm4.dynamics.com/";
UserCredential clientredentials = new UserCredential("****t@******onmicrosoft.com", "****@716");
string client_id = "2b572be0-*****-4581-8481-*******";
AuthenticationContext authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/2ce71a2c-f78d-45c8-9d23-****f/oauth2/v2.0/authorize");
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, client_id, clientredentials);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
httpClient.BaseAddress = new Uri("https://orgf65ea8ad.api.crm4.dynamics.com/api/data/v9.2/");
account_creation_1 ac_1 = new account_creation_1()
{
name = account_Creation.name,
preetham_reasonforregistration = account_Creation.reason_for_registration,
preetham_DepartmentId = Guid.Parse(account_Creation.Department),
preetham_doctorId = Guid.Parse(account_Creation.Doctor)
};
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,new Uri("https://*****.api.crm4.dynamics.com/api/data/v9.2/accounts"))
{
Content = new StringContent(ac_1.ToString(), Encoding.UTF8, "application/json")
};
var response = httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead).Result;
if (response.IsSuccessStatusCode)
{
Console.Write("Account Created");
}
}
I have tested url is correct and i am getting the access token, everything works fine, can anyone help me where i am wrong
Reply
Answers (
0
)
asp.net core display bootstrap tabs dynamically in razor pages
WEB API and WCF