Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Issue connecting Dynamics 365 web api

Posted on by Microsoft Employee

Hi, I have registered for free trial of Microsoft Dynamics 365 and get a URL of dynamics. I am trying to connect to dynamics web api but getting error unauthorized, "AADSTS70001: Application with identifier '' was not found" in the directory." I did not have any other details except the URL which i received during registration  of dynamics. Can you please help on the issue. I think i need clientid to connect. How can I get my clientid? Thanks

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue connecting Dynamics 365 web api

    Hello,

    I written one JS Code  this code is working fine Form level page is  but, in User Interface am getting Error.

    //==============================================================

    //In Order Entity Total DD Instalment records Count is automayically.

    //=============================================================

    function RefreshTotalInstallmentsField(executionContext) {

       try {

           var formContext = executionContext.getFormContext();

           var countOnForm = formContext.getAttribute("new_totalinstalment").getValue();

           var OrderId = formContext.data.entity.getId().replace('{', '').replace('}', '');

           Xrm.WebApi.online.retrieveMultipleRecords("new_directdebitinstalment", "?$select=new_id&$filter=_new_directdebitrenewalid_value eq '" + OrderId + "'").then(

               function success(results) {

                   if (results.entities.length != countOnForm) {

                       CalculateTotalInstallmentsRollupField(executionContext);

                   }

               },

               function (error) {

                   Xrm.Utility.alertDialog(error.message);

               }

           );

       } catch (e) {

           console.log(e.message);

       }

    }

    function CalculateTotalInstallmentsRollupField(executionContext) {

       try {

           var formContext = executionContext.getFormContext();

           var OrderId = formContext.data.entity.getId().replace('{', '').replace('}', '')

           var parameters = {};

           var target = {};

           target.salesorderid = OrderId; //Delete if creating new record

           target["@odata.type"] = "Microsoft.Dynamics.CRM.salesorder";

           parameters.Target = target;

           parameters.FieldName = "new_totalinstalment";

           var calculateRollupFieldRequest = {

               Target: parameters.Target,

               FieldName: parameters.FieldName,

               getMetadata: function () {

                   return {

                       boundParameter: null,

                       parameterTypes:

                       {

                           "Target": {

                               "typeName": "mscrm.crmbaseentity",

                               "structuralProperty": 5

                           },

                           "FieldName": {

                               "typeName": "Edm.String",

                               "structuralProperty": 1

                           }

                       },

                       operationType: 1,

                       operationName: "CalculateRollupField"

                   };

               }

           };

           Xrm.WebApi.online.execute(calculateRollupFieldRequest).then(

               function success(result) {

                   if (result.ok) {

                       var results = JSON.parse(result.responseText);

                       formContext.data.refresh();

                   }

               },

               function (error) {

                   Xrm.Utility.alertDialog(error.message);

               }

           );

       } catch (e) {

           console.log(e.message);

       }

    }

  • PDCM Profile Picture
    PDCM 325 on at
    RE: Issue connecting Dynamics 365 web api

    I'm not actually sure how you can send a request via dynamics API if you don't have Client ID/Application ID, but this is how I made it work. Pretty sure every trial has an AD even if you log-in with your work account. I'm referring to Native App/Web App from my previous message.

               AuthenticationContext authContext = new AuthenticationContext(authResource, token);            

               var result = authContext.AcquireToken(resource, clientID, new Uri(redirectURL));

               using (httpClient = new HttpClient())

               {

                   httpClient.BaseAddress = new Uri(resource);

                   httpClient.Timeout = new TimeSpan(0, 2, 0);

                   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", result.AccessToken);

                   var record = new JObject();

                   record.Add("firstname", "Admin");

                   record.Add("lastname", "Test");

                   record.Add("emailaddress1", "admin@test.com");

                   HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "api/data/v8.2/leads");

                   request.Content = new StringContent(record.ToString());

                   request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                   HttpResponseMessage response = await httpClient.SendAsync(request);

               }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue connecting Dynamics 365 web api

    To establish connection, I am using below code from sdk helper

    Configuration config = null;

               if (cmdargs.Length > 0)

                   config = new FileConfiguration(cmdargs[0]);

               else

                   config = new FileConfiguration(null);

               Authentication auth = new Authentication(config);

               httpClient = new HttpClient(auth.ClientHandler, true);

               httpClient.BaseAddress = new Uri(config.ServiceUrl + "api/data/v8.0/");

               httpClient.Timeout = new TimeSpan(0, 2, 0);

               httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");

               httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");

               httpClient.DefaultRequestHeaders.Accept.Add(

                new MediaTypeWithQualityHeaderValue("application/json"));

    After creating the connection, just doing GET request

    HttpResponseMessage response = httpClient.GetAsync("accounts?$select=*&$top=1", HttpCompletionOption.ResponseContentRead).Result;

    While doing Get request getting the exception shared in above message.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Issue connecting Dynamics 365 web api

    Could you please share your requirement? How are you connecting?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue connecting Dynamics 365 web api

    Thanks for the revert. I have signed in to Dynamics 365 trial using my work account. So in a way it's a SAAS model and there is no way I can register it in Azure AD. I have just got an URL (Dynamics 365) and my work account credentials to login-in. Please guide me further.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue connecting Dynamics 365 web api

    Thanks for the revert. APP here is Dynamics 365 trial, which I have signed in using my work account. So in a way it's a SAAS model and there is no way I can register it in Azure AD. I have just got an URL (Dynamics 365) and my work account credentials to login-in. Please guide me further.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Issue connecting Dynamics 365 web api

    Hi Barinderjit,

    Refer this link: ansrikanth.com/.../connect-to-dynamics-crm-365-webapi-from-console-application

    Hope this helps.

  • PDCM Profile Picture
    PDCM 325 on at
    RE: Issue connecting Dynamics 365 web api

    Hi,

    Have you created an APP in your Azure Active Directory? That is where you can get your Client ID/Application ID.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans