// Call the Contentstack Analytics API to run the data query for the current month
// Current date
const currentDate = new Date();
// Formatting function
const formatDate = (date) => date.toISOString().split("T")[0];
// Calculate and format dates directly
const startOfCurrentMonthFormatted = formatDate(
new Date(currentDate.getFullYear(), currentDate.getMonth(), 1)
);
const endOfCurrentMonthFormatted = formatDate(
new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 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=" +
input.orgUid +
"&from=" +
startOfCurrentMonthFormatted +
"&to=" +
endOfCurrentMonthFormatted +
"&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.