npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nutriot/bandcamp-api

v0.5.5

Published

TypeScript library for interacting with the Bandcamp API

Downloads

8

Readme

@nutriot/bandcamp-api

Library for interacting with the Bandcamp API

License Version: npm Version: jsr Build: NodeJS Build: Deno

Installation

npm install --save @nutriot/bandcamp-api

Prerequisites

In order to make API calls, you need to register to get client ID and secret.

Usage

[!CAUTION]
You should never use this library in the browser to avoid leaking your API credentials!

Import and initialize the Bandcamp module

import Bandcamp from "@nutriot/bandcamp-api";

const api = new Bandcamp({
	id: "<YOUR_CLIENT_ID>",
	secret: "<YOUR_CLIENT_SECRET>",
});

Methods

getClientCredentials()

Usage: getClientCredentials()

Returns access token and refresh token. Both expire after one hour.

const { access_token, refresh_token } = await api.getClientCredentials();

refreshToken()

Usage: refreshToken(refreshToken)

Access tokens expire after one hour. You can use the refresh token to get a new access token.

await api.refreshToken(refresh_token);

getMyBands()

Usage: getMyBands(accessToken)

Returns a list of the bands you have access to (either through artist accounts, label accounts, or partnerships).

await api.getMyBands(access_token);

getSalesReport()

Usage: getSalesReport(accessToken, requestBody)

Returns your sales reports for a label, band, or artist

await api.getSalesReport(access_token, {
	band_id: 1633770804,
	member_band_id: 1925197437,
	start_time: "2015-12-31 23:59:59",
	end_time: "2016-01-31 00:00:00",
});

getMerchDetails()

Usage: getMerchDetails(accessToken, requestBody)

Returns merchandise a label, band, or artist has available for purchase on Bandcamp

await api.getMerchDetails(access_token, {
	band_id: 1633770804,
	start_time: "2015-12-31",
	end_time: "2016-01-01",
	member_band_id: 1925197437,
	package_ids: [175167691, 1154611570],
});

getShippingOriginDetails()

Usage: getShippingOriginDetails(accessToken, requestBody)

Returns the shipping origins for artists and labels linked to your account on Bandcamp

await api.getShippingOriginDetails(access_token);

getOrders()

Usage: getOrders(accessToken, requestBody)

Returns merchandise orders placed with a band or label

await api.getOrders(access_token, {
	band_id: 1633770804,
});

updateShipped()

Usage: updateShipped(accessToken, itemsArray)

Updates shipped/unshipped status of merchandise orders

await api.updateShipped(access_token, [
	{
		id: 1925197437,
		id_type: "p",
		shipped: true,
		notification_message: "Your items have shipped!",
		ship_date: "2016-02-29 12:59:59",
		carrier: "UPS",
		tracking_code: "VM13243546US",
	},
	{
		id: 4261657553,
		id_type: "s",
		shipped: false,
	},
]);

markDateRangeAsShipped()

Usage: markDateRangeAsShipped(accessToken, requestBody)

Updates shipped/unshipped status of merchandise orders within given date range

await api.markDateRangeAsShipped(access_token, {
	band_id: 2293737955,
	member_band_id: 4261657553,
	start_time: "2015-12-31 23:59:59",
	end_time: "2016-01-31 00:00:00",
	email_notifications: true,
});

updateQuantities()

Usage: updateQuantities(accessToken, itemsArray)

Updates merch items' stock quantities (inventory levels)

Note: Because of the inherent race condition, this method requires you pass in a quantity_sold parameter as well as quantity_available.

await api.updateQuantities(access_token, [
	{
		id_type: "p",
		id: 3387163565,
		quantity_available: 365,
		quantity_sold: 57,
		origin_id: 12345698,
	},
	{
		type: "o",
		id: 6789054322,
		quantity_available: 45,
		quantity_sold: 12,
		origin_id: 12345678,
	},
]);

updateSKU()

Usage: updateSKU(accessToken, itemsArray)

Updates merch item stock-keeping unit (SKU)

await api.updateSKU(access_token, [
	{
		id: 175167691,
		id_type: "p",
		sku: "AFIB",
	},
	{
		id: 1154611570,
		id_type: "o",
		sku: "AFIB-XL",
	},
]);

Validators

This library includes a set of experimental validators for the API. Since the responses are undocumented at this point, the validators are not guaranteed to be correct (PRs are welcome!)

Future versions of this library will create its types from these validator schemas.

Valibot

import * as validators from "@nutriot/bandcamp-api/schema/valibot";

Zod

import * as validators from "@nutriot/bandcamp-api/schema/zod";

License

This work is licensed under The MIT License.