Posts

Showing posts with the label #d365

How to Call D365 Custom API from C#

Image
To call a Dynamics 365 (D365) custom API from C#, you can follow the steps outlined below: 1.Import the necessary namespaces: using System; using System.Net.Http; using System.Threading.Tasks; 2. Create an instance of the HttpClient class: HttpClient httpClient = new HttpClient(); 3. Set the base URL of your D365 environment and the API endpoint: string baseApiUrl = "https://your-d365-environment-url/api/data/v9.1"; string apiEndpoint = "/your-custom-api-endpoint"; 4. Set the request headers, including the authorization header if required: httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0"); httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0"); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); // Add any other required headers, such as authorization 5. Make the HTTP request to the custom API endpoint: HttpResponseMessage r...