Forum Discussion
Get Data from cURL with Power Query
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/servicesI 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
jsonResponsebut 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!
- simcla3 years agoRegular Visitor
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!