We are trying to create a CSV file with products from a warehouse.
We have the Json files, we GET all data, but we did not found a way to create a custom CSV with all these informations , Like product name, title, description, price, currency, image1,2,3 , atributes etc
If youâre trying to gather more information on how to create these files and use these in the Collection runner with your requests - You can get more information about this over on our learning site.
All you need to do is basically build the csv manually in the test script and then send it over to the local server which will write it to a file (server is already included as a github repo which youâll find in the documentation link above and you can use that for your use-case).
Next, you need to change the fileExtension that is there for the Write Response To File collection,
Right click the Write Response To File collection > Edit > Tests
You can copy this test script inside and move it to your requestâs test script.
Now, change the fileExtension to csv and then write your csv data that instead of the response body.
the thing I donât get is that the products info and picture links are in one collection and product atributes are into another collection, so we need these in one csv or excel
Well, there are 2 solutions that I can think of right now.
Solution 1: (Easier to do)
Youâll need to modify the node server code (the one that you cloned from GitHub) to actually take the file, read the contents and update each csv entry with the correct picture link.
You can also write your own small server to do that, in case youâre not familiar with javascript and node then you can write your own small file server to actually do that.
Steps would be:
Write all the product data from your PRODUCTS - Get Info as CSV to the file, also write a blank entry for productLink for each item which will be filled in later.
When you send the second request for picture links i.e PRODUCTS - Get Properties, you just need to parse the csv, update each entry with the correct picture link and then save it back to the file.
Solution 2: (Might take a bit longer but would be a good implementation as also all your data will be stored in the cloud)
You can actually make use of the Google Spreadsheets and itâs APIs to create this whole file over the fly.
Google Spreadsheets API docs: Create a spreadsheet | Google Sheets | Google for Developers
You can send the data to the local server which will call the spreadsheet API and write the data directly to a google spreadsheet file.
Then you can directly export your spreadsheet as a CSV.
Now that Visualizations are out officially, I found a nice and simpler way of creating a CSV output using a handlebar template and got inspired by the description in the docs:
Most of my suggested approach and code is based on the suggested reference formerly shared:
With such visualizer in place, after sending the request, in the responseâs body tab, one can choose the âVisualizeâ option of display to see the desired formatted csv file, ready to âSelect All â Copyâ and paste/use wherever needed (as well into a Google Spreadsheet).
In general I think the new Visualization feature in general, and the given free-form handlebars templates is a very useful functionality and opens up a whole new world for us
Could the Visualizer be used to visualize the results of a collection runner, especially one or more console.log outputs from hundreds of iterations of the runner?