SteamAPI Cloudflare Workers
A nice steam api wrapper that works on Cloudflare Workers
Setup
Installation
npm i steamapi-cloudflare-workers
Getting an API Key
Once signed into Steam, head over to http://steamcommunity.com/dev/apikey to generate an API key.
Usage
First, we start by making a SteamAPI "user". (The URLs shown below are the defaults and can be omitted, however for webapps, it may be useful to set up a proxy server to bypass CORS restrictions)
import SteamAPI from 'steamapi-cloudflare-workers';
const steamClient = new SteamAPI(steamWebApiKey, {
baseURL: 'https://api.steampowered.com',
baseStoreURL: 'https://store.steampowered.com/api'
headers: {}
});
Now, we can call methods on SteamAPI
.
For example, let's retrieve the SteamID64 of a user. SteamAPI provides a resolve
method, which accepts URLs and IDs.
SteamAPI.resolve('https://steamcommunity.com/id/DimGG').then(id => {
console.log(id); // 76561198146931523
});
Now let's take that ID, and fetch the user's profile.
steam.getUserSummary('76561198146931523').then(summary => {
console.log(summary);
/**
PlayerSummary {
avatar: {
small: 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/7f/7fdf55394eb5765ef6f7be3b1d9f834fa9c824e8.jpg',
medium: 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/7f/7fdf55394eb5765ef6f7be3b1d9f834fa9c824e8_medium.jpg',
large: 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/7f/7fdf55394eb5765ef6f7be3b1d9f834fa9c824e8_full.jpg'
},
steamID: '76561198146931523',
url: 'http://steamcommunity.com/id/DimGG/',
created: 1406393110,
lastLogOff: 1517725233,
nickname: 'Dim',
primaryGroupID: '103582791457347196',
personaState: 1,
personaStateFlags: 0,
commentPermission: 1,
visibilityState: 3
}
*/
});
Documentation
SteamAPI
Kind: global class
-
Documentation
-
SteamAPI
- new SteamAPI(key, [options])
- steamAPI.get(path, [base], [key]) ⇒
Promise.<Object>
- steamAPI.resolve(info) ⇒
Promise.<string>
- steamAPI.getAppList() ⇒
Promise.<Array.<App>>
- steamAPI.getFeaturedCategories() ⇒
Promise.<Array.<Object>>
- steamAPI.getFeaturedGames() ⇒
Promise.<Object>
- steamAPI.getGameAchievements(app) ⇒
Promise.<Object>
- steamAPI.getGameDetails(app, [force]) ⇒
Promise.<Object>
- steamAPI.getGameNews(app) ⇒
Promise.<Array.<Object>>
- steamAPI.getGamePlayers(app) ⇒
Promise.<number>
- steamAPI.getGameSchema(app) ⇒
Promise.<Object>
- steamAPI.getServers(host) ⇒
Promise.<Array.<Server>>
- steamAPI.getUserAchievements(id, app) ⇒
Promise.<PlayerAchievements>
- steamAPI.getUserBadges(id) ⇒
Promise.<PlayerBadges>
- steamAPI.getUserBans(id) ⇒
Promise.<(PlayerBans|Array.<PlayerBans>)>
- steamAPI.getUserFriends(id) ⇒
Promise.<Array.<Friend>>
- steamAPI.getUserGroups(id) ⇒
Promise.<Array.<string>>
- steamAPI.getUserLevel(id) ⇒
Promise.<number>
- steamAPI.getUserOwnedGames(id) ⇒
Promise.<Array.<Game>>
- steamAPI.getUserRecentGames(id) ⇒
Promise.<Array.<RecentGame>>
- steamAPI.getUserServers([hide], [key]) ⇒
Promise.<PlayerServers>
- steamAPI.getUserStats(id, app) ⇒
Promise.<PlayerStats>
- steamAPI.getUserSummary(id) ⇒
Promise.<PlayerSummary>
-
SteamAPI
new SteamAPI(key, [options])
Sets Steam key for future use.
Param | Type | Default | Description |
---|---|---|---|
key | string |
Steam key | |
[options] | Object |
{} |
Optional options for caching and warnings getGameDetails()
|
[options.enabled] | boolean |
true |
Whether caching is enabled |
[options.expires] | number |
86400000 |
How long cache should last for in ms (1 day by default) |
[options.disableWarnings] | boolean |
false |
Whether to suppress warnings |
Promise.<Object>
steamAPI.get(path, [base], [key]) ⇒ Get custom path that isn't in SteamAPI.
Kind: instance method of SteamAPI
Returns: Promise.<Object>
- JSON Response
Param | Type | Default | Description |
---|---|---|---|
path | string |
Path to request e.g '/IPlayerService/GetOwnedGames/v1?steamid=76561198378422474' | |
[base] | string |
"this.baseAPI" |
Base URL |
[key] | string |
"this.key" |
The key to use |
Promise.<string>
steamAPI.resolve(info) ⇒ Resolve info based on id, profile, or url. Rejects promise if a profile couldn't be resolved.
Kind: instance method of SteamAPI
Returns: Promise.<string>
- Profile ID
Param | Type | Description |
---|---|---|
info | string |
Something to resolve e.g 'https://steamcommunity.com/id/xDim' |
Promise.<Array.<App>>
steamAPI.getAppList() ⇒ Get every single app on steam.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<App>>
- Array of apps
Promise.<Array.<Object>>
steamAPI.getFeaturedCategories() ⇒ Get featured categories on the steam store.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<Object>>
- Featured categories
Promise.<Object>
steamAPI.getFeaturedGames() ⇒ Get featured games on the steam store
Kind: instance method of SteamAPI
Returns: Promise.<Object>
- Featured games
Promise.<Object>
steamAPI.getGameAchievements(app) ⇒ Get achievements for app id.
Kind: instance method of SteamAPI
Returns: Promise.<Object>
- App achievements for ID
Param | Type | Description |
---|---|---|
app | string |
App ID |
Promise.<Object>
steamAPI.getGameDetails(app, [force]) ⇒ Get details for app id. Requests for this endpoint are limited to 200 every 5 minutes
Kind: instance method of SteamAPI
Returns: Promise.<Object>
- App details for ID
Param | Type | Default | Description |
---|---|---|---|
app | string |
App ID | |
[force] | boolean |
false |
Overwrite cache |
Promise.<Array.<Object>>
steamAPI.getGameNews(app) ⇒ Get news for app id.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<Object>>
- App news for ID
Param | Type | Description |
---|---|---|
app | string |
App ID |
Promise.<number>
steamAPI.getGamePlayers(app) ⇒ Get number of current players for app id.
Kind: instance method of SteamAPI
Returns: Promise.<number>
- Number of players
Param | Type | Description |
---|---|---|
app | string |
App ID |
Promise.<Object>
steamAPI.getGameSchema(app) ⇒ Get schema for app id.
Kind: instance method of SteamAPI
Returns: Promise.<Object>
- Schema
Param | Type | Description |
---|---|---|
app | string |
App ID |
Promise.<Array.<Server>>
steamAPI.getServers(host) ⇒ Get every server associated with host.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<Server>>
- Server info
Param | Type | Description |
---|---|---|
host | string |
Host to request |
Promise.<PlayerAchievements>
steamAPI.getUserAchievements(id, app) ⇒ Get users achievements for app id.
Kind: instance method of SteamAPI
Returns: Promise.<PlayerAchievements>
- Achievements
Param | Type | Description |
---|---|---|
id | string |
User ID |
app | string |
App ID |
Promise.<PlayerBadges>
steamAPI.getUserBadges(id) ⇒ Get users badges.
Kind: instance method of SteamAPI
Returns: Promise.<PlayerBadges>
- Badges
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<(PlayerBans|Array.<PlayerBans>)>
steamAPI.getUserBans(id) ⇒ Get users bans.
Kind: instance method of SteamAPI
Returns: Promise.<(PlayerBans|Array.<PlayerBans>)>
- Ban info
Param | Type | Description |
---|---|---|
id |
string | Array.<string>
|
User ID(s) |
Promise.<Array.<Friend>>
steamAPI.getUserFriends(id) ⇒ Get users friends.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<Friend>>
- Friends
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<Array.<string>>
steamAPI.getUserGroups(id) ⇒ Get users groups.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<string>>
- Groups
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<number>
steamAPI.getUserLevel(id) ⇒ Get users level.
Kind: instance method of SteamAPI
Returns: Promise.<number>
- Level
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<Array.<Game>>
steamAPI.getUserOwnedGames(id) ⇒ Get users owned games.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<Game>>
- Owned games
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<Array.<RecentGame>>
steamAPI.getUserRecentGames(id) ⇒ Get users recent games.
Kind: instance method of SteamAPI
Returns: Promise.<Array.<RecentGame>>
- Recent games
Param | Type | Description |
---|---|---|
id | string |
User ID |
Promise.<PlayerServers>
steamAPI.getUserServers([hide], [key]) ⇒ Gets servers on steamcommunity.com/dev/managegameservers using your key or provided key.
Kind: instance method of SteamAPI
Returns: Promise.<PlayerServers>
- Servers
Param | Type | Default | Description |
---|---|---|---|
[hide] | boolean |
false |
Hide deleted/expired servers |
[key] | string |
"this.key" |
Key |
Promise.<PlayerStats>
steamAPI.getUserStats(id, app) ⇒ Get users stats for app id.
Kind: instance method of SteamAPI
Returns: Promise.<PlayerStats>
- Stats for app id
Param | Type | Description |
---|---|---|
id | string |
User ID |
app | string |
App ID |
Promise.<PlayerSummary>
steamAPI.getUserSummary(id) ⇒ Get users summary.
Kind: instance method of SteamAPI
Returns: Promise.<PlayerSummary>
- Summary
Param | Type | Description |
---|---|---|
id | string |
User ID |