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
Komi
Frequent Visitor

Get Data from cURL with Power Query

Hi, I need help - I have a cURL and I need to transform it into a power query.

Can someone please help me?

 

curl --request POST \
  --url https://api.abcd.com/2/ \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'authorization: Bearer xyz' \
  --data '{"query":"query ($period: PeriodFreeInput!) { workspace (id:  \"2ihQOg3IwTBE\") { shifts ( period: $period ) { userName, userId, workTime, period { start, end }, user { email } } } }\n\n","variables":{"period":{"start":"2022-03-31T22:00:00.000Z","end":"2022-04-30T21:59:59.999Z"}}}'
9 REPLIES 9
Syndicate_Admin
Administrator
Administrator

I recently had the same question which I have found the answer to.

Step 1: In Excel select Data\New Query\From Other Sources\From Web

Step 2: Select the "Advanced" radio button

Step 3: Paste the url into the "URL parts" text box

Step 4: Under the heading "HTTP request header parameters (optional) do the following:

- type in the word Authorization into the 1st dropdown box. Next to this type in the word Bearer followed by your required parameter.  It's important you include the word Bearer as well as the parameter that follows it. Eg. Bearer xyz

Make sure there are no quotes around it.

-  type in the words Content-Type into the 2nd dropdown box. Next to this type in the words application/json 

Make sure there are no quotes around it.

Step 5: Click the OK button

Assuming that was successful this will take you into Power Query

Step 6: Click on the "Source" step & then click on the "To Tables" button seen in the next screenshot & Click the "Insert" button

Step 7: Then Click "Ok" as there are no delimiters.

Given that your question was only to do with how do you fetch data using a Curl api request using Power Query I will stop there as I will assume that with the access to the data now achieved that you know how to use Power Query to proceed further.

I hope this helps.  My problem now is finding out how to run many Curl api's automatically one after another.

Thank you for this solution!

I tried to use it to access HomeAssistant using the API interface.

The Curl-Statement is as follows and works fine:

curl \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9....." \
  -H "Content-Type: application/json" \
  http://homeassistant:8123/api/services

 I did translate it in PowerQuery to this statement:

let
    url = "http://homeassistant:8123/api/services",
    headers = [Authorization="Bearer eyJhbGciOiJIUzI1NiIsInR5cC....", 
               #"Content-Type"="application/json"],
    response = Web.Contents(
        url,
        [ Headers = headers ]
    ),
    jsonResponse = Json.Document(response)
in
    jsonResponse

but only got this message:

Unerwarteter Fehler.: Die Blocklänge stimmt nicht mit ihrem Komplement überein.
Details:
    Microsoft.Mashup.Evaluator.Interface.ErrorException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. ---> 
Microsoft.Mashup.Evaluator.Interface.ErrorException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. ---> 
Microsoft.Mashup.Evaluator.Interface.ErrorException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. ---> 
Microsoft.Mashup.Evaluator.Interface.ErrorException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. ---> 
Microsoft.Mashup.Evaluator.Interface.ErrorException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. ---> 
System.IO.InvalidDataException: Die Blocklänge stimmt nicht mit ihrem Komplement überein. --->
System.IO.InvalidDataException: Die Blocklänge stimmt nicht mit ihrem Komplement überein.
   bei System.IO.Mashup.Compression.Inflater.DecodeUncompressedBlock(Boolean& end_of_block)
   bei System.IO.Mashup.Compression.Inflater.Decode()
   bei System.IO.Mashup.Compression.Inflater.Inflate(Byte[] bytes, Int32 offset, Int32 length)
.........................

 Sorry, the error message is in german. It reads something like

"Unexpected Error. The block length does not match its complement."

 

Any idea what is wrong with my code ?

Thanks in advance! 

 

In the meanwhile I found a solution. You have to add

#"Accept-Encoding" = "gzip"

to your code:

let
    url = "http://homeassistant:8123/api/history/period?filter_entity_id=sensor.xxxxx",
    headers = [Authorization="Bearer eyJhbGciOiJIUzI1NiIsI....", 
               #"Content-Type"="application/json",
               #"Accept-Encoding" = "gzip"],
    response = Web.Contents(
        url,
        [ Headers = headers ]
    ), ............................

 

Thanks to Chris Webb!

https://blog.crossjoin.co.uk/2023/02/05/the-block-length-does-not-match-with-its-complement-error-in....

 

Syndicate_Admin
Administrator
Administrator

sorry I didn't know that. I will create a new post. 

Syndicate_Admin
Administrator
Administrator

Hello 

I have an intranet website that has a button to download a file in CSV. 

Can I use power BI to trigger this function in the website to fetch the CSV file and transform it into a table I can manipulate later? If it is doable what info you might need from me to help me? thank you 

Please do not hijack posts. Create a new post.

lbendlin
Super User
Super User

Komi
Frequent Visitor

Thanks, I've been looking at it, unfortunately I don't know how to write the query part. 😞

Without access to your API it is not possible to help you further. You can use Postman or similar for developing the required format.

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
Top Kudoed Authors