https://github.com/greguz/node-bungie-net-api
Yet another Bungie.NET API client for Node.js
https://github.com/greguz/node-bungie-net-api
Last synced: 8 months ago
JSON representation
Yet another Bungie.NET API client for Node.js
- Host: GitHub
- URL: https://github.com/greguz/node-bungie-net-api
- Owner: greguz
- License: mit
- Created: 2022-09-29T10:41:14.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-18T19:24:15.000Z (over 3 years ago)
- Last Synced: 2025-02-24T16:54:41.028Z (over 1 year ago)
- Language: JavaScript
- Size: 469 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-bungie-net-api
[](https://www.npmjs.com/package/bungie.net)

[](https://standardjs.com)
Yet another Bungie.NET API client for Node.js
## Features
- **OAuth support**
- **Support both Private and Public Apps**
- **Automatic token refresh**
- **TypeScript support**
- **Full API surface**: all API are dynamically generated using the official [OpenAPI](https://github.com/Bungie-net/api) specs file.
## OpenAPI
All API methods' are dynamically generated from the official OpenAPI specs.
The currenctly used specs file is also included inside this repository for preservation.
**Current version**: v2.17.0
## Install
```
npm install bungie.net
```
## Documentation
- See the [API documentation](./docs/BungieApi.md).
## Example
```javascript
import { BungieApi, DestinyComponentType } from 'bungie.net'
const api = new BungieApi({
apiKey: 'myapikey',
clientId: 'myclientid',
clientSecret: 'myclientsecret'
})
async function foo () {
// This request does not require user authorization
const manifest = await api.destiny2.getDestinyManifest()
// Redirect the user to this url...
const url = api.getAuthorizationUrl('MySecretState')
// Wait for callback with the authorization code and your state...
const code = 'CallbackRequestQuerystringCode'
await api.authorize(code)
console.log(api.accessToken.raw) // raw token value
console.log(api.accessToken.expires) // expiration date (ms)
console.log(api.accessToken.expired) // false
if (api.refreshToken) {
// If the app is private and everything is configured correctly,
// you'll also get a refresh token from the authorization request
console.log(api.refreshToken.raw)
console.log(api.refreshToken.expires)
console.log(api.refreshToken.expired)
}
// Having an access token, you can request protected resources
const memberships = await api.user.getMembershipDataForCurrentUser()
const membershipType = memberships.destinyMemberships[0].membershipType
const membershipId = memberships.destinyMemberships[0].membershipId
// Get characters from the current authorized profile
const characters = await api.destiny2.getProfile(
membershipType,
membershipId,
{
components: [
DestinyComponentType.Characters
]
}
)
// Grab first characted data
const characterId = Object.keys(characters.characters.data)[0]
const characterData = characters.characters.data[characterId]
// Banshee
const vendorHash = '672118013'
// Get vendor data
const vendorData = await api.destiny2.getVendor(
membershipType,
membershipId,
characterId,
vendorHash,
{
components: [
DestinyComponentType.VendorSales,
DestinyComponentType.ItemPerks
]
}
)
}
foo().catch(err => console.error(err))
```