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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors