Forum Discussion

anandsharma's avatar
anandsharma
New Member
1 year ago
Solved

Getting Error while updating datasource using Rest APIs

I was trying to update Datasource path for Dataverse dataset using rest api but getting error while using below payload payload = {   "updateDetails": [     {       "datasourceSelector": {     ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,anandsharma .I am glad to help you.
    Due to my work environment, I was unable to use a dataverse data source that replicates your actual environment, so I implemented this API using a SQL Server database:

    Datasets - Update Parameters In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

    This API enables you to modify the data source by modifying the value of a parameter in your report.
    1. You need to create a parameter to store the data source information for your report.
    I named it DatabaseName, and the parameter value is AdventureWorksDW2017.



    2. You need to use this parameter in your power query Advanced Editor to replace the original data source name to get the data source (the use of the parameter can make the management of the data source more convenient, you only need to change the data source parameter to modify the data source, which is also the work of the implementation of this API)


    After publish to Power BI Service, you can see that the original data source is AdventureWorksDW2017.


    Meanwhile I successfully configured the gateway connection


    copy the power BI service web url groupID:


    You need to get the ID of the DataSet used by the report you want to modify.
    Use another API:
    Datasets - Get Datasets In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

    This API is a get request, you need to enter the groupID you just entered to get to this DataSet.



    After the API runs successfully, find the corresponding report that needs to be modified and copy the corresponding id value (DataSetID).



    Use the API that I recommend for you:
    Datasets - Update Parameters In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn


    JSON post request body:

    Retrieve the parameter defined in the report: “DatabaseName”, change the value of the parameter
    representing the data source to the new data source you need to modify.

     

    {
      "updateDetails": [
        {
          "name": "DatabaseName",
          "newValue": "AdventureWorksDW2022"
        }
      ]
    }

     


    After a successful run, refresh your browser and subsequently go back to the Power BI Service and view the report's data source, where the modification has successfully occurred (the parameter was modified successfully)

     

    Since I had previously created separate gateway connections for both databases (2017 and 2022), the system automatically changed the database gateway connections when it detected a change in the data source (switching to database 2022)

    The data source was successfully modified by using the API (by modifying the data source parameters)

    I hope my test will give you good advice, I have also uploaded my test file.

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.