Skip to content

Instantly share code, notes, and snippets.

@michalkozminski
Created May 31, 2021
Embed
What would you like to do?
function FETCH_DATA(pentest) {
var url = 'https://api.cobalt.io/findings?pentest='+pentest;
var params = { headers: {
'Accept': 'application/vnd.cobalt.v1+json',
'Content-Type': 'application/vnd.cobalt.v1+json',
'Authorization': 'Bearer YOUR_TOKEN',
'X-Org-Token': 'YOUR_ORG_TOKEN'
}}
var sheet = SpreadsheetApp.getActiveSheet();
var response = JSON.parse(UrlFetchApp.fetch(url, params)).data;
sheet.appendRow(Object.keys(response[0].resource));
response.forEach((i) =>
sheet.appendRow(
Object.entries(i.resource)
.map(([key, content]) => {
if(key == 'labels') {
return content.map(c => c.name).join(',');
}
if(key == 'affected_targets') {
return content.join(',');
}
if(key == 'log') {
return JSON.stringify(content);
}
return content;
})
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment