Hello everyone, I am here because I just started with MongoDB, and I am on a web3 project trying to send data to my database using functions inside triggers, this is because I wish to call an API that gets information from a user that has my NFT and the API uses the following code:
exports = function(changeEvent) {
const http = require('https');
const options = {
method: 'GET',
hostname: 'deep-index.moralis.io',
port: null,
path: '/api/v2/nft/address/owners?chain=eth&format=decimal',
headers: {
accept: 'application/json',
'X-API-Key': 'example'
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on('data', function (chunk) {
chunks.push(chunk);
});
res.on('end', function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
};
So my idea was to use this API into a function on a trigger so that I can set it to update the users from time to time (thinking that they could have trade their NFTs with someone else). But I still don’t know if this is possible, and if I am able to send the information that this API return to create my collection inside my database.
So my question are:
Is this possible? (resume: call an api inside a function to send data to my collection and trigger this function from time to time)
If the answer is yes, then how can I do it (what is the code I should use for to get this data and send to my collection) or what informations should I look for to figure this out?
Another important thing to ask is if there’s a better option or an easy way to do this rs?
Note: The API returns an array with the elements:
Thank you in advance.