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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
CrazyCraigo
Frequent Visitor

Import Dataflow JSON via Power BI Rest API with Powershell

Does anyone have a recent example of performing and import of a dataflow json to a given workspace using powershell. I'm thinking really about this API - 

https://learn.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group#post-import-example

 

I have come across various examples each with their own nuances around the the multipart form-data vs application/json. I even get some to seemingly give me the a dataflow id back but there is no dataflow in the service. If I call  getdataflow using the id I get and empty response. 

 

My use case is that I want to export a dataflow thats my master but then load it into another capacity (I'm using embedded) for another customer as the original source data structures are the same except the data will come via different gateways with different credentials. This all work fine manually exporting and importing via the services but it would be great to add the dataflow via script for expediency. 

 

1 ACCEPTED SOLUTION
CrazyCraigo
Frequent Visitor

For anyone else coming across this issue the solution turned out to be (thanks to some help and guidance from microsoft support) to remove the "partitions" section at the bottom of the import json file. 

 

Steps to get there were 

 

1. Export the dataflow as JSON.

2. Change the  allowNativeQueries value to be "false" (you get a clear warning about this)

3. Remove the partition section at the bottom of the file

4. Use Postman to submit the file

 

Since I to perform this action via powershell I was able to export the required powershell comments from postman saving me having to fight with how to submit the multipart post. 

 

It should also be noted that when you submit the dataflow the id you get back is the "Import ID". Not the dataflow ID as first thought. This ID can be submitted to the 

 

https://api.powerbi.com/v1.0/myorg/groups/{workspaceid}/imports/{importid} endpoint with returns the status iof the import including the dataflow id once its finally succeded. 

View solution in original post

4 REPLIES 4
CrazyCraigo
Frequent Visitor

For anyone else coming across this issue the solution turned out to be (thanks to some help and guidance from microsoft support) to remove the "partitions" section at the bottom of the import json file. 

 

Steps to get there were 

 

1. Export the dataflow as JSON.

2. Change the  allowNativeQueries value to be "false" (you get a clear warning about this)

3. Remove the partition section at the bottom of the file

4. Use Postman to submit the file

 

Since I to perform this action via powershell I was able to export the required powershell comments from postman saving me having to fight with how to submit the multipart post. 

 

It should also be noted that when you submit the dataflow the id you get back is the "Import ID". Not the dataflow ID as first thought. This ID can be submitted to the 

 

https://api.powerbi.com/v1.0/myorg/groups/{workspaceid}/imports/{importid} endpoint with returns the status iof the import including the dataflow id once its finally succeded. 

CrazyCraigo
Frequent Visitor

I have turned to trying with postman and I use this url 

 

https://api.powerbi.com/v1.0/myorg/groups/<workspaceId>/imports?datasetDisplayName=model.json

 

I pass the bearer token. 

I add the model.json as exported from the power bi service.

 

I hit send and I get this seemingly valid response 

 

{
    "id""<a guid>"
}

 

This then seems like it has worked (I have also seen this effect via powershell) but when I check the workspace there is no dataflow to be seen. I also checked in the space I exported the dataflow form in case it somehow end up there...note that I changed the name in the model.json file. 

 

Any ideas? 

Futher to this I checked the activity logs via the Get-PowerBIActivityEvent call and I get the following

{
"Id": "a567a083-d325-4192-bae3-bbeb2f5a1f57",
"RecordType": 20,
"CreationTime": "2024-05-08T12:32:04Z",
"Operation": "Import",
"OrganizationId": "<org id>",
"UserType": 0,
"UserKey": "<my user key>",
"Workload": "PowerBI",
"UserId": "<admins username>",
"ClientIP": "51.104.25.176",
"UserAgent": "PostmanRuntime/7.38.0",
"Activity": "Import",
"ItemName": "dataflowImport",
"WorkSpaceName": "Target Scratchpad",
"CapacityId": "<capacity id>",
"CapacityName": "developmentscratchpad",
"WorkspaceId": "<my target workspace Id>",
"ObjectId": "dataflowImport",
"ImportId": "f8c51eb5-c415-4cb1-bc79-cc724a50fa8a",
"ImportSource": "File",
"ImportType": "Dataflow",
"ImportDisplayName": "dataflowImport",
"IsSuccess": true,
"RequestId": "9866468c-b29d-4bf2-b67d-8e3f72ff557f",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"RefreshEnforcementPolicy": 0
}

 

which looks an awful lot like it was successful. The workspace Id all lines up etc but no dataflow in the workspace and nothing returned from GetDataflow -WorkspaceId <workspace id>

 

v-huijiey-msft
Community Support
Community Support

Hi @CrazyCraigo ,

 

To import a file, specify the content type multipart/form-data in the request header and encode the file as form-data in the request body.

 

Specify the Url parameter for the imported API endpoint and use the Post method.

 

For specific steps and examples, please refer to the official documents below:

Imports - Post Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors