0.5.0 • Published 3 years ago

node-valorant-api v0.5.0

Weekly downloads
104
License
ISC
Repository
github
Last release
3 years ago

node-valorant-api

A NodeJs wrapper for the Riot VALORANT API Active Development

NPM Version

Disclaimer:

As of 2020/08/13, the VAL-MATCH-V1 API is not yet released to the public. Since I don't have the key to test the API, the functionality of this API wrapper is not yet confirmed. You are welcome to open issues regarding problems/bugs/improvements of this wrapper.

However, I have tested the VAL-CONTENT-V1 API which works fine :D

Installation

npm:

npm i node-valorant-api

yarn:

yarn add node-valorant-api

Supported APIs:

All API methods will return a promise containing the return data. For detailed information about the Promise API, please refer to https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Promise

ACCOUNT-V1

MethodDescription
getAccountByPuuid(puuid)Get account by puuid
getAccountByRiotID(gameName, tagLine)Get account by riot id
getActiveShardByPuuid(puuid)Get active shard for a player

VAL-CONTENT-V1

MethodDescription
getContent(locale?)Get content optionally filtered by locale

VAL-MATCH-V1

MethodDescription
getMatchById(matchid)Get match by id
getMatchesByPuuid(puuid)Get matchlist for games played by puuid
getRecentMatches(queue)Get recent matches

VAL-RANKED-V1

MethodDescription
getLeaderboardsByAct(actId, size?, startIndex?)Get leaderboard for the competitive queue

Supported regions:

Valorant API:

RegionEndpoint
APACap.api.riotgames.com
BRbr.api.riotgames.com
EUeu.api.riotgames.com
KRkr.api.riotgames.com
LATAMlatam.api.riotgames.com
NAna.api.riotgames.com
PBE1pbe1.api.riotgames.com

Account API:

RegionEndpoint
ASIAasia.api.riotgames.com
AMERICASamericas.api.riotgames.com
EUROPEeurope.api.riotgames.com

Usage

CommonJs:
const { API, Regions, Locales, Queue } = require("node-valorant-api");

const APIKey = "RGAPI-5aca53b4-d92b-11ea-87d0-0242ac130003"; // Your API Key

// The third parameter is the Region for the Account API
// choose the one that is the closest to you
const valorant = new API(Regions.NA, APIKey, Regions.AMERICAS); // An API instance for Valorant query

// Example usage of the VAL-CONTENT-V1 API
valorant.ContentV1.getContent(Locales["en-US"]).then(content => {
    console.log(content.characters.map(char => { return char.name }));
});

// Example usage of the ACCOUNT-V1 and VAL-MATCH-V1 API !!! The MatchV1 API requires a Production API Key
valorant.AccountV1.getAccountByRiotID("SoLo", "HK1").then(account => {
    valorant.MatchV1.getMatchesByPuuid(account.puuid).then(matches => {
        console.log(matches);
    })
});

/**
 * Example usage of the VAL-STATUS-V1 API
 * https://developer.riotgames.com/apis#val-status-v1/GET_getPlatformData
 */
valorant.StatusV1.getPlatformData().then(data => {
    console.log(data);
});

/**
 * Example usage of the VAL-MATCH-V1 API
 * Queue: "competitive", "unranked", "spikerush"
 * https://developer.riotgames.com/apis#val-status-v1/GET_getPlatformData
 */
valorant.MatchV1.getRecentMatches(Queue.Competitive).then(data => {
    console.log(data);
})
Typescript:
import { API, Regions, Locales, Queue, RiotAPIError } from "node-valorant-api";

const APIKey = "RGAPI-5aca53b4-d92b-11ea-87d0-0242ac130003"; // Your API Key

// The third parameter is the Region for the Account API
// choose the one that is the closest to you
const valorant = new API(Regions.NA, APIKey, Regions.AMERICAS); // An API instance for Valorant query

// Example usage of the VAL-CONTENT-V1 API
valorant.ContentV1.getContent(Locales["en-US"]).then(content => {
    console.log(content.characters.map(char => { return char.name }));
}).catch((error: RiotAPIError) => {
    // Error handling
    console.log(error.status_code);
})

// Example usage of the ACCOUNT-V1 and VAL-MATCH-V1 API !!! The MatchV1 API requires a Production API Key
valorant.AccountV1.getAccountByRiotID("SoLo", "HK1").then(account => {
    valorant.MatchV1.getMatchesByPuuid(account.puuid).then(matches => {
        console.log(matches);
    })
});

/**
 * Example usage of the VAL-STATUS-V1 API
 * https://developer.riotgames.com/apis#val-status-v1/GET_getPlatformData
 */
valorant.StatusV1.getPlatformData().then(data => {
    console.log(data);
});

/**
 * Example usage of the VAL-MATCH-V1 API
 * Queue: "competitive", "unranked", "spikerush"
 * https://developer.riotgames.com/apis#val-status-v1/GET_getPlatformData
 */
valorant.MatchV1.getRecentMatches(Queue.Competitive).then(data => {
    console.log(data);
})

Error Handling

The wrapper will return a Promise rejection with RiotAPIError which can be used to handle Rate Limiting (HTTP Status 429),etc. Every request should include a catch block for handling error.

RiotAPIError has following properties:

interface RiotAPIError {
    request: {
        method: string; // Request Method
        path: string; // Request path
        header: string; // Request headers
        url: string; // Full Request URL
    },
    status_code: number; // Status Code, see https://developer.riotgames.com/docs/portal#web-apis_response-codes
    message: string; // Error message from Riot API
}
0.5.0

3 years ago

0.4.0

4 years ago

0.3.5

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago