Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sdy603/ca428660cd3ac9734e065eee657ae0f5 to your computer and use it in GitHub Desktop.
Save Sdy603/ca428660cd3ac9734e065eee657ae0f5 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
const fs = require('fs');
const csv = require('csv-parser');
const csvFilePath = 'CSV TEMPLATE';
const apiEndpoint = 'CUSTOMER SPECIFIC INCIDENTS SYNC ENDPOINT';
const apiKey = 'API KEY';
fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (row) => {
const incidentData = {
reference_id: row.reference_id,
name: row.name,
started_at: row.started_at,
resolved_at: row.resolved_at,
source_url: row.source_url || '',
services: row.services ? row.services.split(',') : []
};
console.log('Request Body:', JSON.stringify(incidentData, null, 2)); // Print formatted JSON
fetch(apiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(incidentData)
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error));
})
.on('end', () => {
console.log('CSV file successfully processed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment