This is a wrapper for the official MyAnimeList REST API V2. All the endpoints as defined in the documentation are supported including OAuth 2.0 authorization.
npm install myanimelist-api
Generate API credentials by following these instructions.
Make sure to check the resource access is as per your requirements to prevent misuse of the API Keys.
const MyAnimeList = require('myanimelist-api');
const mal = new MyAnimeList({
'clientId': '<Your MAL Client ID>',
'clientSecret': '<Your MAL Client Secret>',
});
Option | Type | Required | Description |
---|---|---|---|
clientId |
String |
yes | Your API Client ID |
clientSecret |
String |
yes | Your API Client Secret |
accessToken |
String |
yes | Your API Access Token |
refreshToken |
String |
yes | Your API Refresh Token |
timeout |
Number |
no | Request Timeout |
axiosConfig |
Object |
no | Reference |
Requests are made with Axios library with support to promises. Error Handling is same as how Axios handles it.
Since MAL V2 API uses oAuth 2 for authorization, you need to access MAL Web Page to allow your user to interact with your app.
const { challengeCode, url } = mal.auth.getChallenge();
In the above snippet, challengeCode
is a PKCE compliant 128 character key which is generated in the getChallenge()
function.
The user needs to be redirected to the url
returned in the above snippet where they need to login with their MAL ID and allow access to your app.
After that, you will receive a code
in the redirect URL from MAL.
Now, using that code
and the challengeCode
, you need to do the following:
const { data } = await mal.auth.getRefreshToken(code, challengeCode);
The data
has the access token as well as the refresh token.
const { data } = await mal.auth.refreshAccessToken(refreshToken);
To reissue the refresh token, you need to re-authorize your user on MAL, Follow from step 1.
To use the following methods, it is assumed that you have your access token as well as the refresh token, so you need to initialize the package a little differently.
const MyAnimeList = require('myanimelist-api');
const mal = new MyAnimeList({
accessToken: "<Your access token>",
refreshToken: "<Your refresh token>",
});
const { data } = await mal.anime.details(11757, options);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | |
options | Object | No | Reference |
const { data } = await mal.anime.list("Your Name", options);
Parameter | Type | Required | Reference |
---|---|---|---|
key | String | Yes | |
options | Object | No | Reference |
const { data } = await mal.anime.seasonal("summer", 2012, options);
Parameter | Type | Required | Reference |
---|---|---|---|
season | String | Yes | Can be summer , winter , fall , spring |
year | Number | Yes | |
options | Object | No | Reference |
const { data } = await mal.anime.ranking("all", options);
Parameter | Type | Required | Reference |
---|---|---|---|
rankingType | String | Yes | Follow Reference Below |
options | Object | No | Reference |
const { data } = await mal.anime.suggestions(options);
Parameter | Type | Required | Reference |
---|---|---|---|
options | Object | No | Reference |
const { data } = await mal.manga.details(21479, options);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | |
options | Object | No | Reference |
const { data } = await mal.manga.list("Your Name", options);
Parameter | Type | Required | Reference |
---|---|---|---|
key | String | Yes | |
options | Object | No | Reference |
const { data } = await mal.manga.ranking("all", options);
Parameter | Type | Required | Reference |
---|---|---|---|
rankingType | String | Yes | Follow Reference Below |
options | Object | No | Reference |
const { data } = await mal.forum.boards(options);
Parameter | Type | Required | Reference |
---|---|---|---|
options | Object | No | Reference |
const { data } = await mal.forum.topics(options);
Parameter | Type | Required | Reference |
---|---|---|---|
options | Object | Yes | Reference |
const { data } = await mal.forum.details(17876, options);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | |
options | Object | No | Reference |
const { data } = await mal.user.details(username, options);
Parameter | Type | Required | Reference |
---|---|---|---|
username | String | No | Defaults to @me |
options | Object | No | Reference |
const { data } = await mal.user.listAnime(username, options);
Parameter | Type | Required | Reference |
---|---|---|---|
username | String | No | Defaults to @me |
options | Object | No | Reference |
const { data } = await mal.user.updateAnime(11757, body);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | |
body | Object | Yes | Reference |
const { data } = await mal.user.deleteAnime(11757);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | Reference |
const { data } = await mal.user.listManga(username, options);
Parameter | Type | Required | Reference |
---|---|---|---|
username | String | No | Defaults to @me |
options | Object | No | Reference |
const { data } = await mal.user.updateManga(11757, body);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | |
body | Object | Yes | Reference |
const { data } = await mal.user.deleteManga(11757);
Parameter | Type | Required | Reference |
---|---|---|---|
id | Number | Yes | Reference |