myanimelist-api
v1.0.1
Published
A wrapper for Official MyAnimeList REST API V2.
Downloads
32
Maintainers
Readme
MyAnimeList API
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.
Installation
npm install myanimelist-api
Getting started
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.
Setup
Initializing the client
const MyAnimeList = require('myanimelist-api');
const mal = new MyAnimeList({
'clientId': '<Your MAL Client ID>',
'clientSecret': '<Your MAL Client Secret>',
});
Options
| 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.
Gerenate the Access Token and Refresh Token from Client
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.
Refresh your access 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.
API
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>",
});
Anime
Details of a specific anime
const { data } = await mal.anime.details(11757, options);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | options | Object | No | Reference
Search
const { data } = await mal.anime.list("Your Name", options);
| Parameter | Type | Required | Reference --- | --- | --- | --- key | String | Yes | options | Object | No | Reference
Seasonal Anime
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
Ranking
const { data } = await mal.anime.ranking("all", options);
| Parameter | Type | Required | Reference --- | --- | --- | --- rankingType | String | Yes | Follow Reference Below options | Object | No | Reference
Suggested Anime
const { data } = await mal.anime.suggestions(options);
| Parameter | Type | Required | Reference --- | --- | --- | --- options | Object | No | Reference
Manga
Details of a specific Manga
const { data } = await mal.manga.details(21479, options);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | options | Object | No | Reference
Search
const { data } = await mal.manga.list("Your Name", options);
| Parameter | Type | Required | Reference --- | --- | --- | --- key | String | Yes | options | Object | No | Reference
Ranking
const { data } = await mal.manga.ranking("all", options);
| Parameter | Type | Required | Reference --- | --- | --- | --- rankingType | String | Yes | Follow Reference Below options | Object | No | Reference
Forum
Get Boards
const { data } = await mal.forum.boards(options);
| Parameter | Type | Required | Reference --- | --- | --- | --- options | Object | No | Reference
Get Topics
const { data } = await mal.forum.topics(options);
| Parameter | Type | Required | Reference --- | --- | --- | --- options | Object | Yes | Reference
Get Topic Details
const { data } = await mal.forum.details(17876, options);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes options | Object | No | Reference
User
Details
const { data } = await mal.user.details(username, options);
| Parameter | Type | Required | Reference
--- | --- | --- | ---
username | String | No | Defaults to @me
options | Object | No | Reference
Get Anime List
const { data } = await mal.user.listAnime(username, options);
| Parameter | Type | Required | Reference
--- | --- | --- | ---
username | String | No | Defaults to @me
options | Object | No | Reference
Update Anime List Entry
const { data } = await mal.user.updateAnime(11757, body);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | body | Object | Yes | Reference
Delete Anime List Entry
const { data } = await mal.user.deleteAnime(11757);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | Reference
Get Manga List
const { data } = await mal.user.listManga(username, options);
| Parameter | Type | Required | Reference
--- | --- | --- | ---
username | String | No | Defaults to @me
options | Object | No | Reference
Update Manga List Entry
const { data } = await mal.user.updateManga(11757, body);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | body | Object | Yes | Reference
Delete Manga List Entry
const { data } = await mal.user.deleteManga(11757);
| Parameter | Type | Required | Reference --- | --- | --- | --- id | Number | Yes | Reference