Forum Discussion
Import Dataflow JSON via Power BI Rest API with Powershell
- 2 years ago
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.
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
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>