Forum Discussion

preetisb15's avatar
preetisb15
Frequent Visitor
6 years ago

how to run REST endpoint in M

I am currently trying to achieve the below with M query - is this doable? any suggestions are welcome.. Thanks in advance

 

This is what I need to be able to do

 

1. First I need to run to call a REST endpoint to start the export

   https://xx.yy.io/report/export?filterType=jqlfilter&jqlFilterID=19216&columnsby=statusduration&calendar=normalhours&outputtype=csv 

 

 

2. running the above REST endpoint, the output will look something like the below 

   https://tis.obss.io/rest/export/3kjhrqoi-asd-3rrd34-3rerwr34-94c797e9f590 

 

I need to run the post command output to get to the data table

 

 

 

2 Replies

  • Assuming that your REST service answers with JSON, you would do something like

     

    let
        Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/gateways/" & GatewayId & "/datasources", [Headers=[Authorization=Authorization]])),

     

    It becomes tricky when your request fails or when it succeeds with a malformed response (looking at YOU, MICROSOFT!)

     

    let
           JsonData = try Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/gateways/" & GatewayId & "/datasources/" & ConnectionId & "/status", [Headers=[Authorization=Authorization]])),
           value = if JsonData[Error][Message]="We reached the end of the buffer." then "True" else "False"
        in
            value

     

    In this example "We reached the end of the buffer"  is caused by a blank 200 return, and is actually the desired outcome.

  • preetisb15's avatar
    preetisb15
    Frequent Visitor

    Hi again 

     

    A bit of progress with the Mquerying. this is how my Mquery looks like 

     

     

    When executing the first time, I get the expected results.

    However when refreshing the query, I get a 404 error: 

    Web.Contents failed to get contents pointing to the sourcelink given in 'webdata.2' - any suggestions how to deal with this?

     

    Many thanks in advance