npm install steamgriddb
You can generate an API key on the preferences page.
import SGDB from "steamgriddb";
const client = new SGDB('your_api_key');
Optionally, you can pass an object with some settings:
const client = new SGDB({
key: 'your_api_key',
headers: {
'X-Some-Header': 'Some Value',
},
baseURL: 'https://www.steamgriddb.com/api/v2'
});
Although these code examples use await,
SteamGridDB can also be used with .then()
and .catch()
.
Example
client.getGrids({type: 'game', id: 2254})
.then((grids) => {
console.log(grids);
})
.catch((error) => {
console.error(error);
});
const games = await client.searchGame('Half-Life 2');
Output
[
{
"id": 2254,
"name": "Half-Life 2",
"types": [
"steam"
],
"verified": true
},
{
"id": 21207,
"name": "Half-Life",
"types": [
"steam"
],
"verified": true
},
{
"id": 1417,
"name": "Half-Life: Blue Shift",
"types": [
"steam"
],
"verified": true
},
{
"id": 3868,
"name": "Half-Life: Source",
"types": [
"steam"
],
"verified": true
}
]
// 2254 = Game ID we got from searchGame()
const grids = await client.getGrids({type: 'game', id: 2254});
// 2254 = Game ID we got from searchGame()
const grids = await client.getGridsById(2254);
// Get grid by Steam App Id
// 220 = https://store.steampowered.com/app/220/HalfLife_2/
const grids = await client.getGrids({type: 'steam', id: 220});
// 220 = https://store.steampowered.com/app/220/HalfLife_2/
const grids = await client.getGridsBySteamAppId(220);
const grids = await client.getGrids({type: 'game', id: 2590, styles: ['material','blurred']});
client.getGridsBySteamAppId(220, ['material','blurred'])
Output
[
{
"id": 80,
"score": 1,
"style": "blurred",
"url": "https://s3.amazonaws.com/steamgriddb/grid/f033ab37c30201f73f142449d037028d.png",
"thumb": "https://s3.amazonaws.com/steamgriddb/thumb/f033ab37c30201f73f142449d037028d.png",
"tags": [],
"author": {
"name": "EpicWolverine",
"steam64": "76561198025674497",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/76/764911aeb96ae312c2819780f4107396d3b5ac38.jpg"
}
},
{
"id": 120,
"score": 1,
"style": "blurred",
"url": "https://s3.amazonaws.com/steamgriddb/grid/da4fb5c6e93e74d3df8527599fa62642.png",
"thumb": "https://s3.amazonaws.com/steamgriddb/thumb/da4fb5c6e93e74d3df8527599fa62642.png",
"tags": [],
"author": {
"name": "Tiederian",
"steam64": "76561197997534033",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/bc/bc893073b7e2e60ad412c6fd2af39d3204a5f26a.jpg"
}
}
]
// Delete a grid
const success = await client.deleteGrids(80);
// Delete multiple grids
const success = client.deleteGrids([80,81,82,83]);
SteamGridDB throws an AxiosError when an error occurs, with the message
altered to contain the message returned from SteamGridDB. All methods and properties available in an AxiosError
are available, such as error.request
and error.response
.
// Get grids for a game that doesn't exist
let grids;
try {
grids = await SGDB.getGrids({dimensions: ["460x215", "920x430"], ...{type, id: 0}});
} catch (error) {
console.log(error.message); // "Game not found."
console.log(err.response.status); // 404
};
// Try to delete a grid you don't own
try {
await client.deleteGrids(34312);
} catch (error) {
console.log(error.message); // "This grid isn't yours."
console.log(err.response.status); // 403
}