// pages/api/anime-media-list.js export default async function handler(req, res) { const { username, status } = req.body; try { const response = await fetch("https://graphql.anilist.co/", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ query: ` query ($username: String, $status: MediaListStatus) { MediaListCollection(userName: $username, type: ANIME, status: $status, sort: SCORE_DESC) { user { id name about (asHtml: true) createdAt avatar { large } statistics { anime { count episodesWatched meanScore minutesWatched } } bannerImage mediaListOptions { animeList { sectionOrder } } } lists { status name entries { id mediaId status progress score media { id status title { english romaji } episodes coverImage { large } } } } } } `, variables: { username, status, }, }), }); const data = await response.json(); res.status(200).json(data.data.MediaListCollection); } catch (error) { console.error(error); res.status(500).json({ message: "Internal server error" }); } }