Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Zuv
Frequent Visitor

help need on updating dataset credentials on PowerBI Embedded

I am using PowerBI embedded with rest api calls, all the datasets sits under Azure Sql.

I have written easily rest api calls with php and cURL, like -- detele dataset, upload reports, get workspaces etc. All went smoothly.

 

I got stuck on DirectQuery Reports with updating credentials to it with REST API.

As I know first I need to run Get GetBoundGatewayDatasources operation in order to get Datasource ID and ID and then patch it with a call:

PATCH https://api.powerbi.com/v1.0/collections/mywsc01/workspaces/32960a09-6366-4208-a8bb-9e0678cdbb9d/gateways/ca17e77f-1b51-429b-b059-6b3e3e9685d1/datasources/5f7ee2e7-4851-44a1-8b75-3eb01309d0ea
Authorization: AppKey 9BKsnTVkRP...
Content-Type: application/json; charset=utf-8

{
  "credentialType": "Basic",
  "basicCredentials": {
    "username": "demouser",
    "password": "P@ssw0rd"
  }
}

All seems pretty easy, the problem is I can't get results from this  Get GetBoundGatewayDatasources call, it just says in header 404 not found.

There is an article about all the workflow and they mentions that:

"Note : If the error of 404 Not Found occurs, please change (re-create) the location of the Power BI Embedded resource in Azure Portal. (Please see the note above.)"

Well, I have used workspace under US and other one under WEST EU. Do you have any ideas?

The whole article I fallowed by: https://blogs.msdn.microsoft.com/tsmatsuz/2016/07/20/power-bi-embedded-rest/

 

It's pretty old one, maybe they do have other solutions to update those credentials for datasets (pbix files). Mine datasets sits under Azure SQL and uses DirectQuery.

Seems like they still have path method in documentation as well as GetBoundGatewayDatasources method..

This is my code:

  public function getGatewayDatasource($workspaceId, $datasetId) {

	   				$key = env('ACCESS_KEY');
					$collection_name = env('WORKSPACE_COLLECTION');
					
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_HEADER, 1);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

                    curl_setopt($ch, CURLOPT_URL, "https://api.powerbi.com/v1.0/collections/".$collection_name."/workspaces/".$workspaceId."/".$datasetId."/Default.GetBoundGatewayDatasources");


                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Might be required for https
                    curl_setopt($ch, CURLOPT_HTTPHEADER, [
                        "Authorization: AppKey " . $key
                    ]);
                    $response_json = curl_exec($ch);

                    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

                    curl_close($ch);

                    if ($httpcode == 200) {
                    	$message = 'success';
                    }
                    else {
                    	$message = $response_json;
                    }
                    // $response_data = json_decode($response_json, true);

            return ($response_json);


	   }

If you have any ideas about it, would be great to know. 

Many thanks!

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@Zuv

Those GetBoundGatewayDatasources and GatewayDatasource both work in my test.

When reviewing your code, I've found the the API url is wrong, you're missing the highlighted part.

 

https://api.powerbi.com/v1.0/collections/{collectionName}/workspaces/{workspaceId}/datasets/{datasetKey}/Default.GetBoundGatewayDatasources

Please review your code and ensure that the collectionName, workspaceId and datasetId(some one put a report id here) are all correct.

 

View solution in original post

1 REPLY 1
Eric_Zhang
Employee
Employee

@Zuv

Those GetBoundGatewayDatasources and GatewayDatasource both work in my test.

When reviewing your code, I've found the the API url is wrong, you're missing the highlighted part.

 

https://api.powerbi.com/v1.0/collections/{collectionName}/workspaces/{workspaceId}/datasets/{datasetKey}/Default.GetBoundGatewayDatasources

Please review your code and ensure that the collectionName, workspaceId and datasetId(some one put a report id here) are all correct.

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.