So we get all products, how should we export them in a custom CSV?

#1

Hello everyone in this community, first of all.

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

Would be of help any idea on how to do this.

#2

here is a printscreen of the workspace !

#3

Hey @ogaming,

Welcome to the community :wave:

Just to clarify your question…

Are you trying to create an exportable custom CSV file based on the response body data, from within the application?

Or do you need to create a CSV file with data, to use within the Collection Runner?

#4

I am trying to create a custome CSV file in order to be able and import this file to our site to create products

#5

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.

#6

So, you can basically make use of this template, which helps you with writing a data from postman to a file.

Documentation for Write Response To File: https://documenter.getpostman.com/view/3407886/RWgp1fB5

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).

To convert your JSON response to a csv format, you’ll need to write the script.
This stackoverflow thread has couple of answers which will help you around that: https://stackoverflow.com/questions/8847766/how-to-convert-json-to-csv-format-and-store-in-a-variable

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.

#7

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 :frowning:

1 Like
#8

Oh, I see.

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:

  1. 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.
  2. 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: https://developers.google.com/sheets/api/guides/create
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. :slight_smile:

1 Like