2.1.1 • Published 1 year ago

steamgriddb v2.1.1

Weekly downloads
14
License
MIT
Repository
github
Last release
1 year ago

SteamGridDB API

npm license license

Installation

npm install steamgriddb

Getting Started

Get your API key

You can generate an API key on the preferences page.

Require the library into your project.

import SGDB from "steamgriddb";

Pass your API key into the constructor:

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'
});

Usage

Although these code examples use await, SteamGridDB can also be used with .then() and .catch().

    client.getGrids({type: 'game', id: 2254})
        .then((grids) => {
            console.log(grids);
        })
        .catch((error) => {
            console.error(error);
        });

Search for a game:

const games = await client.searchGame('Half-Life 2');
[
  {
    "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
  }
]

Get grids By Game ID

// 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 grids by Steam App ID

// 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);

Filter styles:

const grids = await client.getGrids({type: 'game', id: 2590, styles: ['material','blurred']});
client.getGridsBySteamAppId(220, ['material','blurred'])
[
  {
    "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 grids:

// Delete a grid
const success = await client.deleteGrids(80);
// Delete multiple grids
const success = client.deleteGrids([80,81,82,83]);

Handling errors:

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
}
2.1.1

1 year ago

2.0.2

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.5.0

2 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago