node-valorant-api
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

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

Method Description
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

Method Description
getContent(locale?) Get content optionally filtered by locale

VAL-MATCH-V1

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

VAL-RANKED-V1

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

Supported regions:

Valorant API:

Region Endpoint
APAC ap.api.riotgames.com
BR br.api.riotgames.com
EU eu.api.riotgames.com
KR kr.api.riotgames.com
LATAM latam.api.riotgames.com
NA na.api.riotgames.com
PBE1 pbe1.api.riotgames.com

Account API:

Region Endpoint
ASIA asia.api.riotgames.com
AMERICAS americas.api.riotgames.com
EUROPE europe.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
}

Package Sidebar

Install

npm i node-valorant-api

Weekly Downloads

7

Version

0.5.0

License

ISC

Unpacked Size

55.7 kB

Total Files

50

Last publish

Collaborators

  • solohk525