Chipmunk JavaScript SDK
Important Note
A Chipmunk account is required to use this SDK. You can sign up for one free here.
Please note that all API tokens currently have the full permissions of a user. Do not deploy API secrets publicly! Read-only public access via the JavaScript SDK is currently in development.
Installation
NPM:
npm install @thinksqurrel/chipmunk
Yarn:
yarn add @thinksquirrel/chipmunk
Usage
Basic usage
var chipmunk = require("@thinksquirrel/chipmunk").chipmunk;
var apiKey = "XXXXX"; // Your API key, under User Profile > API Keys
var apiSecret = "XXXXX"; // API secret, do not share this value
chipmunk.config({ apiKey, apiSecret });
chipmunk.collections
.getAll()
.request()
.then(function(collectionList) {
console.log("%s collection(s) total:", collectionList.count);
collectionList.result.forEach(function(collection) {
console.log(
" - %s: %s",
collection.title,
collection.summary || "No description available",
);
});
});
Multiple API instances
var chipmunk = require("@thinksquirrel/chipmunk").chipmunk;
var apiKey = "XXXXX"; // Your API key, under User Profile > API Keys
var apiSecret = "XXXXX"; // API secret, do not share this value
const apiInstance = chipmunk.createInstance({ apiKey, apiSecret });
apiInstance.collections
.getAll()
.request()
.then(function(collectionList) {
console.log("%s collection(s) total:", collectionList.count);
collectionList.result.forEach(function(collection) {
console.log(
" - %s: %s",
collection.title,
collection.summary || "No description available",
);
});
});
Downloading a revision
var chipmunk = require("@thinksquirrel/chipmunk").chipmunk;
var apiKey = "XXXXX"; // Your API key, under User Profile > API Keys
var apiSecret = "XXXXX"; // API secret, do not share this value
var assetId = "XXXXX"; // IDs for resources can be discovered through the API
// Initialize
chipmunk.config({ apiKey, apiSecret });
// Get asset information
// In the API, assets are named "items"
chipmunk.items
.get({ id: assetId })
.request()
.then(function(myAsset) {
console.log(
"Downloading '%s' from '%s'...",
myAsset.head.fileName,
myAsset.title,
);
// Download an asset's current revision ("head")
return chipmunk.revisions.get
.download({
id: myAsset.head.id,
})
.request()
.then(function(downloadToken) {
console.log("URL: %s", downloadToken.url); // Temporary URL to the file
});
});
See our API for more details.