Skip to content
AniLink

AniList helpers

Two data helpers live on the anilist namespace: aniLink.anilist.fuzzyDate and aniLink.anilist.flattenMediaListCollection. They are methods on the client, not standalone imports.

fuzzyDate

Builds an AniList FuzzyDateInput from optional year, month, and day parts. AniList represents unknown fuzzy-date parts as 0; this helper fills each omitted part with 0, so the result always satisfies the FuzzyDateInput contract. Use it to construct startedAt/completedAt values for list-entry mutations.

typescript
const aniLink = new AniLink("anilist-token");

const startedAt = aniLink.anilist.fuzzyDate({ year: 2024, month: 4, day: 15 });
// { year: 2024, month: 4, day: 15 }

const yearOnly = aniLink.anilist.fuzzyDate({ year: 2024 });
// { year: 2024, month: 0, day: 0 } — omitted parts become 0

await aniLink.anilist.mutation.saveMediaListEntry({
    mediaId: 1,
    status: "COMPLETED",
    startedAt,
});

All three fields are optional. Pass an empty object (or omit the argument) to produce an all-zero date.

flattenMediaListCollection

mediaListCollection returns lists nested by status and custom list. flattenMediaListCollection flattens that structure into a single array of FlattenedMediaListEntry objects, deduplicated by entry id.

typescript
const aniLink = new AniLink("anilist-token");

const collection = await aniLink.anilist.query.mediaListCollection({
    userId: 542244,
    type: "ANIME",
});

const entries = aniLink.anilist.flattenMediaListCollection(collection);
console.log(entries.length, entries[0]?.listNames);

FlattenedMediaListEntry shape

Each entry carries the list-entry fields and its full list membership — not the embedded media object. To resolve media details, fetch the media by mediaId separately.

FieldTypeDescription
idnumberThe list-entry id
userIdnumberThe owning user's id
mediaIdnumberThe media the entry refers to
statusstringThe entry status (e.g. CURRENT, COMPLETED)
scorenumberThe score assigned
progressnumberEpisodes or chapters watched/read
listNamesstring[]Every list group the entry belongs to (status list name plus any custom lists)
inCustomListbooleantrue when the entry appears in at least one custom list group
inSplitCompletedListbooleantrue when the entry appears in at least one split completed list group

Dedup and list-membership behavior

Entries appearing in multiple status groups are deduplicated by entry id — a media present in both COMPLETED and a custom list yields one entry, with every group name accumulated in listNames. Custom-list-only membership is preserved. Entries are not filtered to the primary status groups.

Next steps

AniLink — typed AniList & MyAnimeList client for TypeScript.