// Call the Contentstack Analytics API to run the data query for the previous month
// Current date
const currentDate = new Date();
// Formatting function
const formatDate = (date) => date.toISOString().split("T")[0];
// Calculate and format previous month's dates directly
const startOfPreviousMonthFormatted = formatDate(
new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1)
);
const endOfPreviousMonthFormatted = formatDate(
new Date(currentDate.getFullYear(), currentDate.getMonth(), 0)
);
var requestOptions = {
method: "GET",
headers: {
api_key: input.apiKey,
authtoken: input.authToken,
"Content-Type": "application/json"
},
redirect: "follow"
};
let result1 = await (
await fetch(
"https://app.contentstack.com/analytics/v2/usage?orgUid=bltd593d22e94735bc7&from=" +
startOfPreviousMonthFormatted +
"&to=" +
endOfPreviousMonthFormatted +
"&duration=month&includeCount=true",
requestOptions
)
).json();
return [result1];
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.