I am trying to get data from a Discord API. The page shows multiple pages, however, there is no page number attribute. Instead, in the header, there is an offset value of 25.
{ “key”: “offset”,
“value”: “25”,
“description”: “” }
So the URL changes from:
https://discord.com/api/v9/guilds/663869392152559648/messages/search?content=upset
to
https://discord.com/api/v9/guilds/663869392152559648/messages/search?content=upset&offset=25
and multiples of 25 for every subsequent page…
I have got the response to the first URL with the following code (Many thanks to Valentine Despa!!! Very grateful for his tutorials ) :
const newman = require('newman'); // require newman in your project
const fs = require('fs');
newman.run({
collection: require('./Discorddata.json'),
reporters: 'cli'
}).on('request', (error, data) => {
if (error) {
console.log(error);
return;
}
const requestName = data.item.name;
const fileName = `response-${requestName}.txt`;
const content = data.response.stream.toString();
fs.writeFile(fileName, content, function (error) {
if (error) {
console.error(error);
}
});
});
I do not know how to use the offset and value to get all the pages. I know I should probably use setNextRequest() but I cannot find anything to help me understand how I can use Newman and setNextRequest.
And even in setNextRequest() how should I specify the request?
Extremely sorry if this is downright dumb. I am very new to the whole web dev and backend stuff and POSTMAN above all!! I need to collect Discord data for my ML project so I am trying to learn how all of this works.
Thank you very much!