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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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