Files
push-adyen-collections-to-p…/postmanLibrary.js
Julien Lengrand-Lambert bb0ac9191d Getting workspace from Postman
2023-03-08 11:48:05 +01:00

42 lines
1.0 KiB
JavaScript

const https = require('https');
exports.getWorkspace= async function(workspaceId, postmanApiKey) {
const options = {
hostname: 'api.getpostman.com',
port: 443,
path: '/workspaces/'+workspaceId,
method: 'GET',
headers: {
'X-Api-Key': postmanApiKey
}
}
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
if (res.statusCode < 200 || res.statusCode >= 300) {
return reject(new Error('statusCode=' + res.statusCode));
}
let body = [];
res.on('data', (chunk) => {
body.push(chunk);
});
res.on('end', () => {
try {
body = JSON.parse(Buffer.concat(body).toString());
} catch (e) {
reject(e);
}
resolve(body);
});
});
req.on('error', (err) => {
reject(err);
});
req.end();
});
}