fortnite-basic-api
Basic Fortnite API for stats and server status built with async/await
Inspired by other repos about Fortnite API's as:
Which I previously used fortnite-api but have gotten issues with unhandledrejections which causing issues in other projects. Therefore I rebuilt with focus on Async/await to resolve the issues and adding support for V2 API endpoint.
BREAKING CHANGES
From v1.5 backward compatibility methods & ways of doing things has been removed. Check the examples how to use it properly.
Example usage:
const { Client, Communicator, FriendStatus } = require('fortnite-basic-api');
const client = new Client({
email: process.env.FORTNITE_EMAIL,
password: process.env.FORTNITE_PASSWORD,
launcherToken: 'MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=',
fortniteToken: 'ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ=',
autokill: true,
});
const communicator = new Communicator(client);
(async () => {
console.log(await client.authenticator.login());
communicator.events.on('session:started', async () => {
console.log('XMPP Client is fully connected');
console.log('Add friend: ', await communicator.friendship.addFriend('iXyles'));
console.log(await communicator.friendship.getFriends());
console.log(await communicator.friendship.getIncomingFriendRequests());
console.log(await communicator.friendship.getOutgoingFriendRequests());
});
communicator.events.on('friend:request', async (friendrequest) => {
if (friendrequest.friendStatus === FriendStatus.INCOMING) {
console.log(friendrequest, await friendrequest.accept());
}
});
communicator.events.on('reconnect', async (failure) => {
if (failure) {
console.log(failure);
}
});
communicator.events.on('friend:added', async (friend) => {
console.log(`You're now friend with: ${friend.accountId}`);
});
communicator.events.on('friend:reject', async (friend) => {
console.log(`You got rejected the friend request by: ${friend.accountId}`);
});
communicator.events.on('friend:removed', async (friend) => {
console.log(`You're now unfriended with: ${friend.accountId}`);
});
communicator.events.on('friend:abort', async (friend) => {
console.log(`Friendrequest aborted with: ${friend.accountId}`);
});
communicator.events.on('friend:presence', (friend) => {
console.log(friend.presence);
});
communicator.events.on('friend:message', async (friend) => {
console.log(await friend.getStatus());
console.log('message', await friend.sendMessage('Send something back'));
});
console.log(await communicator.connect());
const parallel = await Promise.all([
client.stats.getV2Stats('iXyles'),
client.stats.getV2Stats('96afefcb12e14e7fa1bcfab1189eae55'),
client.lookup.accountLookup('iXyles'),
client.lookup.accountLookup('96afefcb12e14e7fa1bcfab1189eae55'),
client.lookup.accountLookup(['iXyles', '96afefcb12e14e7fa1bcfab1189eae55']),
client.getServerStatus(),
client.getBRNews('es'),
client.getBRStore(),
client.getPVEInfo(),
client.getBREventFlags(),
client.authenticator.accountId,
]);
(parallel).forEach((result) => {
console.log(result);
});
})();
License
MIT License
Copyright (c) 2019-2020 iXyles
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.