Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
I've added this post to showcase the CRUD operations in C# through WebAPI endpoint. You must have working experience in below areas: –
All the operations below require access token to be passed as a header hence it's important to know how to use ADAL (Active Directory Azure Authentication Library).
WebAPI (or REST) endpoints are very easy to program as they just require you to know the authentication protocol then it's all about sent HTTP Requests with respective OData Filters. Each operation requires a unique set of URLs to be passed. Below you see a sample for creating a record. You can find completed repository on GitHub.
/// <summary>
/// This function can create any record type using Json Entity Objects
/// </summary>
/// <param name="entityName"></param>
/// <param name="entityObject"></param>
/// <returns></returns>
public async Task CreateEntityRecords(string entityName, JObject entityObject)
{
using (httpClient = CreateDynHttpClient(AccessToken, entityName))
{
HttpRequestMessage createHttpRequest = new HttpRequestMessage(HttpMethod.Post, BaseOrganizationApiUrl + "/api/data/v8.1/" + entityName);
createHttpRequest.Content = new StringContent(entityObject.ToString(), Encoding.UTF8, "application/json");
var response = await httpClient.SendAsync(createHttpRequest);
response.EnsureSuccessStatusCode();
if (response.StatusCode == HttpStatusCode.NoContent)
{
// Do something with response. Example get content:
Console.WriteLine("The record was created successfully.");
Console.ReadKey();
}
}
}
Happy WebAPI'ing :)
Cheers,
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in