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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dyingod
Helper I
Helper I

Call web API, receive ZIP, decompress multiple JSON files, Load Them

Hello everyone,

 

Still a noob... I have a simple question. I searched around the forums and found this discussion as the most relevant but I can't make it work and maybe my case is different so I thought to ask.

 

I have an API connection that I can access via a simple web call:

https://api.bla.com/v2/get.php?action=get&project=Project+Name&date=yyyy-mm-dd&token=token&compressi...

 

This call returns a ZIP file containing many JSON files.

 

Making the call is simple but I get stuck on when I receive the ZIP file... how can I:

  1. Decompress the many JSON files
  2. Get M/PowerQuery to recognise them as JSON files (which we all know it can)
  3. Load them into 1+ tables

Preferably 1 table would be great but I can work with millions of them... My issue is how to go from Step 1 to Step 3. I have tried variations of the forum post I linked above and some other google results like:

As always, I thank & salute you all!

 

Rafa

1 ACCEPTED SOLUTION

@dyingod,

Yes, File.Contents function requires path parameter.

In addition, I haven't found any built-in decompress function that can be used to decompress .zip file. Is there any possibility that your web service return .gzip file? If so, you can use Binary.Decompress to automatically proceed this transformation.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
apo1979prio
Helper I
Helper I

Hello!!!
Only 7 Steps for GET JSON:
let
Source = SharePoint.Files("https://Mysharepoint", [ApiVersion = 15]),
Step01 = Table.SelectRows(Source, each Text.StartsWith([Folder Path], "https://Mysharepoint_SearchFolder/")),
Step02 = Table.SelectColumns(Step01, {"Content", "Name", "Extension", "Folder Path"}),
Step03 = Table.SelectRows(Step02, each [Extension] = ".json"),
Step04 = Table.SelectColumns(Step03, {"Content"}),
Step05 = Table.AddColumn(Step04, "Json", each Json.Document([Content], 65001)),
Step06 = Table.SelectColumns(Step05, {"Json"}),
Step07 = Table.ExpandListColumn(Step06, "Json")
in
Step07

v-yuezhe-msft
Employee
Employee

@dyingod,

Create the unzip function as described in this blog: http://sql10.blogspot.sg/2016/06/reading-zip-files-in-powerquery-m.html . Then invoke the function and create a custom column in the returned table. There is an example for your reference.
1.JPG2.JPG



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey Lydia!

 

Thanks so much for this. I had also looked into that link but couldn't manage to do anything with it.

 

I get stuck here:

 

let
    Source = File.Contents("[Full path to your zip file]"),
    Files = UnzipContents(Source)
in
    Files

 

At the [Full path to your zip file], which make me think of a place in my drive but obviously it's not as it's within Power BI so what do I put in there? I tried calling the query with the ZIP by name but that didn't work. I really am a newbie. 😞

 

I think the Custom Column trick sounds amazing and I never thought that possible... but I need to get over this other obstacle first. Can I call on your awesome help again? 🙂

 

Thank you!


Rafa

Try changing the line:

 

Source = File.Contents(...

 

to:

 

Source = Web.Contents(...

@dyingod,

Is there any possiblity that you download the zip file to your computer from web?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey Lydia,

 

You mean outside PowerQuery? PowerQuery does download it and show it to me as a file:

 2017-11-27 09_49_58-Clipboard.png

 

The reason I'm trying to do it all via Power Query is just so it's automated.

 

Or maybe I am wrong in assuming that file that returns in the screenshot is the actual zip?

 

This is the ZIP file that contains 50+ JSON files I mentioned in the title.

 

Thanks Lydia!

 

Rafa

@dyingod,

Yes, File.Contents function requires path parameter.

In addition, I haven't found any built-in decompress function that can be used to decompress .zip file. Is there any possibility that your web service return .gzip file? If so, you can use Binary.Decompress to automatically proceed this transformation.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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