Skip to main content
Dynamics 365 Community / Forums / Finance forum / Integrate with Microso...
Unanswered

Integrate with Microsoft Dynamics CRM API using ASP.NET Core

editSubscribe (0) ShareShare
ReportReport
Posted on by 8
hellow all :
 
Iam biggner developer in company and they ask me to build app in asp.net to print purchase order from d365 finOps  so ,
 
1- register app in AAD.
my program by GPT chat help 
// in appsettings.json file {  /DynamicsCRM/: {    /BaseUrl/: https://your-crm-instance.api.crm.dynamics.com/api/data/v9.0//,    /ClientId/: /your-client-id/,    /ClientSecret/: /your-client-secret/,    /TenantId/: /your-tenant-id/  }}// in DynamicsCRMService.cs file using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;using Microsoft.Extensions.Configuration;using Newtonsoft.Json;public class DynamicsCRMService{    private readonly HttpClient _httpClient;    public DynamicsCRMService(IConfiguration configuration, HttpClient httpClient)    {        _httpClient = httpClient;        var dynamicsCRMConfig = configuration.GetSection(/DynamicsCRM/);        _httpClient.BaseAddress = new System.Uri(dynamicsCRMConfig[/BaseUrl/]);        _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(/application/json/));    }    public async Task<string> GetPurchaseOrders()    {        var response = await _httpClient.GetAsync(/purchaseorders/);        response.EnsureSuccessStatusCode();        return await response.Content.ReadAsStringAsync();    }}//in program file builder.Services.AddHttpClient<DynamicsCRMService>();builder.Services.AddScoped<DynamicsCRMService>();// DynamicsCRMService controller using Microsoft.AspNetCore.Mvc;using System.Threading.Tasks;[ApiController][Route(/[controller]/)]public class PurchaseOrderController : ControllerBase{    private readonly DynamicsCRMService _dynamicsCRMService;    public PurchaseOrderController(DynamicsCRMService dynamicsCRMService)    {        _dynamicsCRMService = dynamicsCRMService;    }    [HttpGet]    public async Task<IActionResult> GetPurchaseOrders()    {        var purchaseOrders = await _dynamicsCRMService.GetPurchaseOrders();        return Ok(purchaseOrders);    }}
there is no error but not any result in https://localhost:5001/purchaseorder