Tools & Resources
Community
Export Content Model to CSV
You can export a model's content items to a Comma Separated Value file by using a GET request to the cloud function contentToolsModeltoCSV or by writing your own NodeJS script.
get
https://us-central1-zesty-prod.cloudfunctions.net/contentToolsModeltoCSV
Content Model to CSV

Write your Own CSV Export

If you are looking for a more custom export, here is the the node code to export a Content Model to a CSV using the Node SDK.
1
const SDK = require("@zesty-io/sdk");
2
3
const modelZUID = '6-xxx-xxxxx';
4
const instanceZUID = '8-xxx-xxxxx';
5
const authToken = 'XXXXX';
6
7
const sdk = new SDK(instanceZUID, token);
8
let items = await sdk.instance.getItems(modelZUID);
9
10
let header = []
11
let itemData = []
12
13
// start the headers
14
header.push({id: 'zuid', title: 'zuid'})
15
header.push({id: 'url', title: 'url'})
16
// create the csv headers based on the content (data) row
17
for (let [key, value] of Object.entries(items.data[0].data)) {
18
header.push({id: key, title: key});
19
}
20
21
items.data.map(async item => {
22
item.data.url = item.web.path ? item.web.path : null;
23
item.data.zuid = item.meta.ZUID;
24
console.log(item.data)
25
itemData.push(item.data);
26
});
27
28
// take first item and convert it to a header
29
const createCsvStringifier = require('csv-writer').createObjectCsvStringifier;
30
const csvStringifier = createCsvStringifier({
31
header: header
32
});
33
34
let csvstring = csvStringifier.getHeaderString()+csvStringifier.stringifyRecords(itemData);
35
console.log(csvstring);
Copied!
Last modified 1yr ago