Hello dear PBI REST API experts, I would appreciate any support on the following issue.
Trying to send data from MongoDB Atlas to Power BI Push Dataset through Rest API.
However I met the following issue, when I'm making more than 5 post http requests to PBI Rest API it says 'Error: connect: exceeded the limit of 5 sockets'.
I found the following link on this website, however seems like solution was not found there: Close socket connection in request.js
function postDataToPowerBi(result) {
...
collection.findOne({"_id": item._id}).then(itemDoc => {
postOne(itemDoc, access_token);
});
...
}
function postOne(itemDoc, access_token){
var postData = JSON.stringify({
"rows": [
{
"Name": itemDoc.Name,
"name.1": itemDoc.name
}
]
});
// request option
var options = {
host: 'api.powerbi.com' ,
port: 443,
method: 'POST',
path: '/v1.0/myorg/groups/' + group_id + '/datasets/' + dataset_id + '/tables/' + table_name + '/rows',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + access_token,
// 'Content-Length': postData.length,
'Connection': 'Close'
}
};
// request object
var req = https.request(options, function (res) {
var result = '';
res.on('data', function (chunk) {
result += chunk;
});
res.on('end', function () {
console.log(res.statusCode);
});
res.on('error', function (err) {
console.log(err);
});
});
// req error
req.on('error', function (err) {
console.log(err);
});
req.on('close', function () {
console.log("request closed");
});
//send request witht the postData form
req.write(postData);
req.end();
}