-
Hello is there any example of how to get page views from nextjs app? but the question is any idea what is the timestamp mean? I passed the new Date().toISOString() to the start_date and end_date query parameters, but end up getting 500, but when I pass random 10 digits number, nothing goes wrong except I got an empty array of pageviews. here's my code: import axios from 'axios'
import { NextApiRequest, NextApiResponse } from 'next'
const USERNAME = process.env.UMAMI_USERNAME
const PASSWORD = process.env.UMAMI_PASSWORD
const UMAMI_URL = process.env.UMAMI_URL
// axios instance, pre-configured headers and base URL
const umami = axios.create({
baseURL: UMAMI_URL,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
}
})
// get token from umami `/api/auth/login`
const getTokenFromUmami = async (username: string, password: string) => {
const body = { username, password }
try {
const response = await umami.post<{ token: string }>('/api/auth/login', body)
// return null if the status not 200
if (response.status !== 200) {
return null
}
// return the token
return response.data.token
} catch (error) {
return null
}
}
// eslint-disable-next-line import/no-anonymous-default-export
export default async (req: NextApiRequest, res: NextApiResponse) => {
// get token from umami, with given username and password from .env file
const token = await getTokenFromUmami(USERNAME as string, PASSWORD as string)
// if token is null, return 500
if (!token) {
return res.status(500).send({
message: 'Error when trying to get token from umami'
})
}
// get pageviews from umami `/api/website/1/pageviews`
const pageviews = await umami.get(
'/api/website/1/pageviews?start_at=0000000000&end_at=1638230400&unit=day&tz=Asia/Jakarta',
{
headers: { Authorization: `Bearer ${token}` }
}
)
return res.status(200).send(pageviews.data)
} |
Beta Was this translation helpful? Give feedback.
Answered by
mikecao
Apr 21, 2022
Replies: 1 comment 1 reply
-
It is the date timestamp, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rimzzlabs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is the date timestamp,
new Date().getTime()