1.0.1 • Published 4 years ago

myanimelist-api v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

MyAnimeList API

npm version dependencies Status github issues

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

OptionTypeRequiredDescription
clientIdStringyesYour API Client ID
clientSecretStringyesYour API Client Secret
accessTokenStringyesYour API Access Token
refreshTokenStringyesYour API Refresh Token
timeoutNumbernoRequest Timeout
axiosConfigObjectnoReference

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);
ParameterTypeRequiredReference
idNumberYes
optionsObjectNoReference

Search

const { data } = await mal.anime.list("Your Name", options);
ParameterTypeRequiredReference
keyStringYes
optionsObjectNoReference

Seasonal Anime

const { data } = await mal.anime.seasonal("summer", 2012, options);
ParameterTypeRequiredReference
seasonStringYesCan be summer, winter, fall, spring
yearNumberYes
optionsObjectNoReference

Ranking

const { data } = await mal.anime.ranking("all", options);
ParameterTypeRequiredReference
rankingTypeStringYesFollow Reference Below
optionsObjectNoReference

Suggested Anime

const { data } = await mal.anime.suggestions(options);
ParameterTypeRequiredReference
optionsObjectNoReference

Manga

Details of a specific Manga

const { data } = await mal.manga.details(21479, options);
ParameterTypeRequiredReference
idNumberYes
optionsObjectNoReference

Search

const { data } = await mal.manga.list("Your Name", options);
ParameterTypeRequiredReference
keyStringYes
optionsObjectNoReference

Ranking

const { data } = await mal.manga.ranking("all", options);
ParameterTypeRequiredReference
rankingTypeStringYesFollow Reference Below
optionsObjectNoReference

Forum

Get Boards

const { data } = await mal.forum.boards(options);
ParameterTypeRequiredReference
optionsObjectNoReference

Get Topics

const { data } = await mal.forum.topics(options);
ParameterTypeRequiredReference
optionsObjectYesReference

Get Topic Details

const { data } = await mal.forum.details(17876, options);
ParameterTypeRequiredReference
idNumberYes
optionsObjectNoReference

User

Details

const { data } = await mal.user.details(username, options);
ParameterTypeRequiredReference
usernameStringNoDefaults to @me
optionsObjectNoReference

Get Anime List

const { data } = await mal.user.listAnime(username, options);
ParameterTypeRequiredReference
usernameStringNoDefaults to @me
optionsObjectNoReference

Update Anime List Entry

const { data } = await mal.user.updateAnime(11757, body);
ParameterTypeRequiredReference
idNumberYes
bodyObjectYesReference

Delete Anime List Entry

const { data } = await mal.user.deleteAnime(11757);
ParameterTypeRequiredReference
idNumberYesReference

Get Manga List

const { data } = await mal.user.listManga(username, options);
ParameterTypeRequiredReference
usernameStringNoDefaults to @me
optionsObjectNoReference

Update Manga List Entry

const { data } = await mal.user.updateManga(11757, body);
ParameterTypeRequiredReference
idNumberYes
bodyObjectYesReference

Delete Manga List Entry

const { data } = await mal.user.deleteManga(11757);
ParameterTypeRequiredReference
idNumberYesReference
1.0.1

4 years ago

1.0.0

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago