Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Power BI API Dataflow Import Operation

Hi all, I am testing Dataflow creation via API. I am following "Power BI dataflow REST API reference" instructions.

 

I can export a Dataflow via API but when I try to create a Dataflow with Import operation I get this error:

 

  1. Method not allowed. The requested resource does not support http method 'POST'

 

This is the code extracted from Postman App for C# RestSharp library:

 

var client = new RestClient("https://api.PowerBI.com/v1.0/myorg/groups/<mygroupid>/import?datasetDisplayName=DataflowTest.json&type=dataflow&displayName=DataflowTest");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer <mytoken>");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"\"; filename=\"Dataflowtest.json\"\r\nContent-Type: application/json\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

 

Did you get the same error code?

 

Thanks.

  • import is a bit trickey to get right

    here is a sample:

     

    POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/imports?datasetDisplayName=model.json HTTP/1.1
    accept: application/json, text/plain, */*
    cache-control: no-cache
    Authorization: Bearer eyJ0eXAiOi...nQ
    User-Agent: PostmanRuntime/7.3.0
    accept-encoding: gzip, deflate
    content-type: multipart/form-data; boundary=--------------------------613655670645709167014348
    content-length: ...
    Connection: close
     < BODY>
    ----------------------------613655670645709167014348
    Content-Disposition: form-data; name=""; filename="model.json"
    Content-Type: application/json
     
    {
        "name": "my model",
        "version": "1.0",
        ...
    }
    ----------------------------613655670645709167014348--

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

     

     

    This request need to register an azure AD app before using, have you finished register before test?

     

    In addition, I found you add other query string to request url, I check on whitepaper but not found it allow additional query parameters:

    /v1.0/myorg/groups/{groupId}/imports?datasetdisplayName=<name>.json&type=dataflow

     

    Notice: <name>.json should stored dataflow entity structure defined with json formula.

     

    Reference links:

    Developer resources for Power BI dataflows (Preview)

    Register an Azure AD app to embed Power BI content

     

    You can also take a look at following video about dataflow:

     

    Regards,

    Xiaoxin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous,

       

      Thanks for your reply.

       

      Yes, I did the registration process and permission granting. The fact is that I can execute GET commands and the API works as expected.

       

      I added some documentation parameters to the query string I attached in the previous message but in my tests with the documentation url I got this error too.

       

      About the JSON structure, I get it from the export function in PowerBI service, the datasetdisplayName parameter is pointing to that file. The content of the file is sent as form in the request.

       

      About the video, I have watched it carefully but I cant find an explanation about how accessing CDM in default Azure Storage Gen2 (if possible...) can be performed or changing the default Azure Storage Gen2 for a custom Storage. 

       

      Thanks again, I will keep you updated.

  • I too faced the same problem.

     

    GET operations were successful.

    I even tried DELETE dataflow api and it executed fine. So I guess it is not related to permissions.

     

    As per the doc -Power BI dataflow REST API Reference

    The body will contain a model.json file encoded as form data.

     

    I am suspecting issue because of this. I am using POST MAN. I have raw json file. 

    Can someone tell me how to provide json as encoded form data. Do I have to manually give key value pairs?

    Is there easy way to try with POSTMAN tool?

    • amos_ortal's avatar
      amos_ortal
      Resolver I

      import is a bit trickey to get right

      here is a sample:

       

      POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/imports?datasetDisplayName=model.json HTTP/1.1
      accept: application/json, text/plain, */*
      cache-control: no-cache
      Authorization: Bearer eyJ0eXAiOi...nQ
      User-Agent: PostmanRuntime/7.3.0
      accept-encoding: gzip, deflate
      content-type: multipart/form-data; boundary=--------------------------613655670645709167014348
      content-length: ...
      Connection: close
       < BODY>
      ----------------------------613655670645709167014348
      Content-Disposition: form-data; name=""; filename="model.json"
      Content-Type: application/json
       
      {
          "name": "my model",
          "version": "1.0",
          ...
      }
      ----------------------------613655670645709167014348--

  • Hi Anonymous, amos_ortal

     

    I am able to create dataflow using import API in postman tool. In which, I manually fetched authorization token from the browser dev tools.

     

    Now I need to do it through powershell script.
    Could you please tell me how did you get Authorization token in your code? 

     

    I am basically trying to create a powershell script which asks for certain input parameters and then execute post API to create dataflow.

    Thanks.

    • imrannz's avatar
      imrannz
      New Member

      Hi, 

       

      Did you manage to find a solution for this. I am wanting to do exactly what you are looking at but have been un-successful.

       

      Thanks

      • V55's avatar
        V55
        Helper I

        Hi, It worked for me. I tried in PostMan.

         

        URL - Select POST. 

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

         

        Header:

        Authorization - Bearer ... (I fetched it from browser while accessing powerBI)

        Accept - application/json, text/plain, */*

        Content-Type - multipart/form-data

         

        Body:

        Choose form-data and select choose Files button and import your json. While importing, make sure the json has different dataflow name. If existing name is given, it will return error. Thanks.