web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't query data from ...
Power Apps
Unanswered

Can't query data from Dataverse Web API

(0) ShareShare
ReportReport
Posted on 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,

I have the same question (0)
  • ivan_apps Profile Picture
    2,187 Moderator on at

    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

  • ArtiXabi Profile Picture
    13 on at

    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,
  • Verified answer
    ArtiXabi Profile Picture
    13 on at

    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

  • ivan_apps Profile Picture
    2,187 Moderator on at

    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

     

  • suryatejakemi Profile Picture
    4 on at

    Hi ,

     

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




     

     

     

     

     

  • ArtiXabi Profile Picture
    13 on at

    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 at

    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.


  • maxpower45255 Profile Picture
    223 on at

    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. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard