Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

How to parse a application/zip file

AbdulBalogun
7 - Meteor

I have a informatica API that outputs as a application / zip file

 

zip.PNG

 

In postman I can just save that application / zip result as a file (excel) which gives me my real data (columns / values)

save as.PNG

 

Is there a way to parse / unpack that application/zip file within alteryx so get my real data (headers/values) into a browse / output tool?

5 REPLIES 5
apathetichell
18 - Pollux

set your content-type to application/zip in your download tool headers. then set your download tool to download as blob. use blob output to output your file.

 

when you say - real data - if you mean the file you are downloading - you'd need to save it locally with a distinct location. have that location/name in a field - and feed it into a batch macro to open the file (as a zip.).

AbdulBalogun
7 - Meteor

That helps to download a blob but how do I actually see the contents of my application/zip file? like I said in postman I just save the file as a csv then extract the zip file to open my csv and look at the data. Is there a way I can look at the data within the file in Alteryx? or at least unzip it and download as a csv? or some format that's readable? not sure if blob will work

BS_THE_ANALYST
14 - Magnetar

@AbdulBalogun  I think you can use the python tool here.

 

If you've got a zip file, you can use the python tool in alteryx and import the native zipfile module https://docs.python.org/3/library/zipfile.html. You'll just need to construct a zipfile.PyZipFile object i.e. zipfile.PyZipFile("zip_path_here") and then use the method .extract_all on that newly created object: .extractall(path=None) .. just provide the path you want to unzip it to.

 

That should unzip your entire zip file and reveal all the contents. You can then leverage that unzipped directory path either with Python using Pandas to read it into a dataframe or you can just supply the file's path to the directory tool in alteryx with a batch macro .. or just use a file input and point to the unzipped file.

 

If you want to automate it all in the Python tool, I think you can consider using the requests module with the appropriate headers. Then you can feed the response of that using something like:

with open(zip_save_path, "wb") as data:

 data.write(resp.content)

   

that should write the zip contents into a the desired location then you can start using the ZipFile module to extract and then subsequently read your files and do the tabular stuff in alteryx or python

 

All the best,

BS

AbdulBalogun
7 - Meteor

using postman, I receive the zip stream as my Api output, and I can save that as a zip file and extract it to get my excel file. However, in Alteryx when I use the download tool, I think I get that same zip stream but as VSTRING field. I'm at a point in my flow now when I can see the zip stream as a text field in my browse tool (see attached zip picture) so right now I don't have a file, I have a field containing my zip stream, how can I get from this point to seeing the contents of the data?

 

I know you mentioned I can use python If I have a zip file, but I only get that zip file when using postman, will that python method still work for where I am in my workflow?

 

Ive attached pictures of my download tool configuration, current browse tool output, and postman zip stream out (for reference)

apathetichell
18 - Pollux

As I pointed out in my post:

when you say - real data - if you mean the file you are downloading - you'd need to save it locally with a distinct location. have that location/name in a field - and feed it into a batch macro to open the file (as a zip.).

 

Here is an example. This may not work for you. you must configure your batch macro for your style files. You will need to know sample file names (ie a naming structure) for the files in your zip. You will need to know the fileformat of those files. This is not overly different than any other how to work with zip files in Alteryx workflow - and there should be solid resources on that.

Labels