0.5.1 • Published 1 year ago

steamwebapi-wrapper v0.5.1

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

This library provides convenient access to the Steamwebapi REST API from TypeScript or JavaScript.

To learn how to use the Steamwebapi API, check out our API Reference and Documentation.

Table of Contents

Installation

pnpm add steamwebapi-wrapper
# or
npm install steamwebapi-wrapper
# or
yarn add steamwebapi-wrapper

Usage

To use this wrapper, you first need to obtain an API key from the Steam Web API. Follow these steps to get your API key:

  1. Go to the Steam Web API Key Page.
  2. Log in with your Steam account. If you do not have an account, you will need to create one.
  3. Fill in the required information to request an API key. This key will be necessary to access the Steam Web API.

The full API of this library can be found in api.md file along with many code examples. The code below shows how to get started using the Steamwebapi API.

import SteamWebApi from "steamwebapi-wrapper";

// Create instance by providing API Key
const swa = new SteamWebApi({ apiKey: "STEAMWEBAPI_API_KEY" });

// Get Trade Offers
async function main() {
  const offers = await swa.trade.getOffers({ /* options */ });

  console.log(offers.data);
}

main();

Config Defaults

You can specify config defaults that will be applied to every request.

Custom instance defaults

// Set config defaults when creating the instance
const trade = swa.trade.create({ assetid: "ASSET_ID" });

// Override per-request:
await trade.getOffers({ assetid: "NEW_ASSET_ID" });

Global trade defaults

swa.trade.defaults.assetid = "ASSET_ID";
swa.trade.defaults.steamcommunityapikey = "STEAM_COMMUNITY_API_KEY";

Handling Errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of WrapperError will be thrown:

async function main() {
  const offers = await swa.getOffers({
      steamcommunityapikey: "STEAM_COMMUNITY_API_KEY",
    }).catch((err) => {
      if (err instanceof SteamWebApi.APIError) {
        console.log(err.status); // 400
        console.log(err.message); // Unknown Error
      } else {
        throw err;
      }
    });
}

main();

Error codes are as followed:

Status CodeError Type
401Unauthorized access due to missing or invalid steamcommunityapikey
421Missing required parameters or rate limit exceeded
422Invalid JSON format in the request
489Invalid steamcommunityapikey
500Internal server error or unexpected error from the Steam API
N/AAPIConnectionError

Examples

For more examples check the examples directory.

Contributing

Contributions to this project are welcome! If you encounter a bug or have a feature request, feel free to open an issue. Pull requests with improvements or new features are also appreciated.

License

This API wrapper is licensed under the MIT License.

0.5.0

1 year ago

0.5.1

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago