Skip to main content

Notifications

Community site session details

Community site session details

Session Id : R3e0IgaqvRLfZy1GT/yge6
Power Apps - Microsoft Dataverse
Answered

Can't query data from Dataverse Web API

Like (0) ShareShare
ReportReport
Posted on 9 Feb 2024 13:52:36 by 13

Hi

So I'm developing an application and I need to connect to Dataverse in order to retrieve data from custom tables. I'm able to get an access token, but when using the token in following requests I always get 401. Steps I have followed so far:

  • Registered an application in Azure and gave permissions over Dynamics API.
  • Created a secret for the app.
  • Created an application user and assigned corresponding client_id.

From my code I can successfully get an access token. I then include it in a Postman request as Authorization header, and perform a GET https://<org>.api.crm4.dynamics.com/api/data/v9.2/contacts. It always returns 401 - Unauthorized.

I'm developing the app in NodeJS and can't find documentation about it, so any help or guidance would be much appreciated.

 

Thanks in advance!

Regards,

Categories:
  • maxpower45255 Profile Picture
    223 on 29 May 2024 at 13:45:41
    Re: Can't query data from Dataverse Web API

    Hey All,

    I thought of starting a new thread but my issue is similar to this. I was hoping I'd just piggy back on this. 

    I have an issue with getting data back from Dataverse using the Web API. I can connect to the endpoint and get a 200/OK http status. But there is no data returned by the searchquery API. 

    Any thoughts? 

     

    Here's a little more background: 

    I have enabled search in my environment, added a few tables to be indexed via my PowerAutomate solution, then added columns to be indexed using the 'Quick Find' views of my custom tables.

    I can successfully use the global search within my model-driven power app. I can also search using the 'Search rows (preview)' dataverse action in Power Automate. So it seems that I have a perfectly functioning search index. So why isn't the API returning any data? 

     

    Here is the request/response from an "Invoke Http Request with Entra ID" action in Power Automate:
    URI: https://MYENV.crm.dynamics.com

    API:  /api/data/v9.2/searchquery

    Request body: { "top": 10, "count": "true",
    "search": "My keyword here"
    }
     

    Response:
    "body": {
    "@odata.context": "https://MYENV.crm.dynamics.com/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.searchqueryResponse",
    "response": "{\"Error\":null,\"Value\":[],\"Facets\":{},\"QueryContext\":null,\"Count\":0}"
    }

    Thanks in advance. 

  • suryatejakemi Profile Picture
    4 on 16 Feb 2024 at 11:13:05
    Re: Can't query data from Dataverse Web API

    Hi,

    Thanks for replying, I have trouble connecting to the correct Environment while update the data verse table through, Can we please connect over call ?

    Please Provide the contact details for Connecting.


  • ArtiXabi Profile Picture
    13 on 16 Feb 2024 at 10:47:55
    Re: Can't query data from Dataverse Web API

    Hi

    When accessing my Dynamics instance, the URL looks like the following:

    ArtiXabi_0-1708080331367.png

    I don't know why, but sometimes it gives you 4, I have also seen some of them given with 8... I'm not the one deploying Dynamics so maybe it has something to do with the way to do so..

     

    Regards,

  • suryatejakemi Profile Picture
    4 on 16 Feb 2024 at 09:46:03
    Re: Can't query data from Dataverse Web API

    Hi ,

     

     Can you Please let me know, why you kept 4 in the URL.




     

     

     

     

     

  • ivan_apps Profile Picture
    2,187 Super User 2025 Season 1 on 09 Feb 2024 at 14:54:26
    Re: Can't query data from Dataverse Web API

    Understood, that is how it will work once you get the access token properly and query Dataverse, user interaction will not be needed as you will be passing in your App Registration client id and secret. You can even use CBA if you wanted to avoid the secret.

     

    You will want to try to get the Authentication piece/access token working in Postman, perhaps you are missing a configuration in the App Registration to allow it to work - i've followed that article in the past and connected successfully to execute the whoami request. Take a look at the article below to ensure you've done all the steps in your AppReg.

    https://www.matthewdevaney.com/a-visual-guide-to-power-platform-service-principal-setup/

     

    I can also share with you a power automate http connector configuration I have for connecting to GraphAPI - its very similar to yours to connect via OAuth.

     

    ivan_apps_0-1707490075128.png

     

  • Verified answer
    ArtiXabi Profile Picture
    13 on 09 Feb 2024 at 14:42:53
    Re: Can't query data from Dataverse Web API

    Hi all

    So the problem was the URL. I was using ["https://<org>.crm.dynamics.com/.default"], but instead it was ["https://<org>.crm4.dynamics.com/.default"]. I was missing the '4'. I'm now able to retrieve data from Dataverse successfully.

     

    Kind regards

  • ArtiXabi Profile Picture
    13 on 09 Feb 2024 at 14:31:52
    Re: Can't query data from Dataverse Web API

    Hi

    Thanks for answering.

    I'm afraid it's not working. When I select Get Access Token, a window pops asking for user and password. I introduce my credentials and get this:

    ArtiXabi_0-1707488839847.png

    Nevertheless, even if it worked, my goal is to connect from my express server developed in NodeJS, so the authentication should be done by using the access token so the server can retrieve data without user interaction.

     

    In case it's helpful, I'm using the @Anonymous/msal library to get the access token, and configured it as it follows:

     
    public async getAuthToken(): Promise<String> {
        var authToken: String = "";
        const config = {
          auth: {
            clientId: process.env.CLIENT_ID,
            clientSecret: process.env.SECRET,
          },
        };
        const cca = new msal.ConfidentialClientApplication(config);

        const tokenRequest = {
        };
        const resp = await cca
          .acquireTokenByClientCredential(tokenRequest)
          .then((response) => {
            authToken = response.accessToken;
          });
        return authToken;
     
    Maybe I'm getting the token from the wrong URL?
     
    Thanks in advance.
    Regards,
  • ivan_apps Profile Picture
    2,187 Super User 2025 Season 1 on 09 Feb 2024 at 14:16:48
    Re: Can't query data from Dataverse Web API

    Take a look at this article - it should walk you through how to set up your postman environment to connect to dataverse and send requests for testing. It seems like you've properly set up the App Reg for the environment so just follow the remaining steps.

     

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/setup-postman-environment

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
SadFox Profile Picture

SadFox 2

#1
stampcoin Profile Picture

stampcoin 2

Overall leaderboard

Featured topics