@bynder/bynder-js-sdk

中文文档
2.5.8发布于 2026/09/14MITCommonJS近 30 天下载 7.5万

Bynder Javascript SDK

原始使用文档
文档目录18 节
  1. Requirements
  2. Installation
  3. Node.js
  4. Usage
  5. Available methods
  6. Authentication
  7. Media
  8. Media usage
  9. Metaproperties
  10. Collections
  11. Tags
  12. Smartfilters
  13. Brands
  14. Upload
  15. Contribute to the SDK
  16. Docker Setup
  17. Initial Setup
  18. Sample Files

Bynder JavaScript SDK

Tests Publish

This SDK aims to help the development of integrations with Bynder that use JavaScript, providing an easy interface to communicate with Bynder's REST API.

Requirements

To use this SDK, you will need:

Node installation will include NPM, which is responsible for dependency management.

Installation

Node.js

npm install @bynder/bynder-js-sdk

import Bynder from '@bynder/bynder-js-sdk';

Usage

This SDK relies heavily on Promises, making it easier to handle the asynchronous requests made to the API. The SDK provides a Bynder object containing several methods which map to the calls and parameters described in Bynder's API documentation.

The following snippet is a generic example of how to use the SDK. If you need details for a specific module, refer to the samples folder.

Before executing any request, you need to authorize the calls to the API:

Using a permanent token

const bynder = new Bynder({
  baseURL: "https//portal.getbynder.com/api/",
  permanentToken: "<token>",
});

Using OAuth2

  1. Call the constructor with your configuration
const bynder = new Bynder({
  baseURL: "https://portal.getbynder.com/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>",
  redirectUri: "<url where user will be redirected after authenticating>"
});
  1. Create an authorization URL, login and get one-time authorization code
const authorizationURL = bynder.makeAuthorizationURL();
  1. Exchange code for an access token
bynder.getToken(code);

If you already have an access token, you can also initialize Bynder with the token directly:

const bynder = new Bynder({
  baseURL: "http://api-url.bynder.io/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>",
  redirectUri: "<url where user will be redirected after authenticating>",
  token: "<OAuth2 access token>"
});

OAuth2 Client Credentials

OAuth application within Bynder needs client credentials grant type. Bynder object can be instantiated without redirectUri provided:

const bynder = new Bynder({
  baseURL: "http://api-url.bynder.io/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>"
});

To get a token via client credentials, make a call to getTokenClientCredentials():

const bynder = new Bynder({
  baseURL: "http://api-url.bynder.io/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>"
});
const token = await bynder.getTokenClientCredentials();

Sample call can be found within samples/oauth_client_credentials.js.

Making requests

You can now use the various methods from the SDK to fetch media, metaproperties and other data. Following the Promises notation, you should use .then()/.catch() to handle the successful and failed requests, respectively.

Most of the calls take an object as the only parameter but please refer to the API documentation to tune the query as intended.

bynder
  .getMediaList({
    type: "image",
    limit: 9,
    page: 1
  })
  .then(data => {
    // TODO Handle data
  })
  .catch(error => {
    // TODO Handle the error
  });

Available methods

Authentication

  • makeAuthorizationURL()
  • getToken()
  • getTokenClientCredentials()

Media

  • getMediaList(queryObject)
  • getMediaInfo(queryObject)
  • getAllMediaItems(queryObject)
  • getMediaTotal(queryObject)
  • editMedia(object)
  • deleteMedia(id)

Media usage

  • getAssetUsage(queryObject)
  • saveNewAssetUsage(queryObject)
  • deleteAssetUsage(queryObject)

Metaproperties

  • getMetaproperties(queryObject)
  • getMetaproperty(queryObject)
  • saveNewMetaproperty(object)
  • editMetaproperty(object)
  • deleteMetaproperty(object)
  • saveNewMetapropertyOption(object)
  • editMetapropertyOption(object)
  • deleteMetapropertyOption(object)

Collections

  • getCollections(queryObject)
  • getCollection(queryObject)
  • saveNewCollection(queryObject)
  • shareCollection(queryObject)
  • addMediaToCollection(queryObject)
  • deleteMediaFromCollection(queryObject)

Tags

  • getTags(queryObject)

Smartfilters

  • getSmartfilters(queryObject)

Brands

  • getBrands()

Upload

  • uploadFile(fileObject)

Contribute to the SDK

If you wish to contribute to this repository and further extend the API coverage in the SDK, here are the steps necessary to prepare your environment:

  1. Clone the repository
  2. In the root folder, run yarn install to install all of the dependencies.
  3. Create a secret.json file with the following structure:
{
  "baseURL": "http://api-url.bynder.io/api/",
  "clientId": "<your OAuth2 client id>",
  "clientSecret": "<your OAuth2 client secret>",
  "redirectUri": "<url where user will be redirected after authenticating>"
}
  1. The following gulp tasks are available:
  • gulp lint - Run ESlint and check the code.
  • gulp build - Run webpack to bundle the code in order to run in a browser.
  • gulp babel - Run Babel to create a folder 'dist' with ES2015 compatible code.
  • gulp doc - Run JSDoc to create a 'doc' folder with automatically generated documentation for the source code.
  • gulp webserver - Deploy a web server from the root folder at localhost:8080 to run the html samples (in order to avoid CORS problems).

Docker Setup

JavaScript files can be executed within a Docker container with corresponding dependencies installed.

Initial Setup

From the root directory create a secret.json file.

{
  "baseURL": "http://api-url.bynder.io/api/",
  "clientId": "<your OAuth2 client id>",
  "clientSecret": "<your OAuth2 client secret>"
}

Run the command make run-docker to start up Docker container.

With the container running, execute the command:

make executeSdkSample sample-file-name=oauth_client_credentials.js where sample-file-name is the name of the file within samples/. This command will execute the JavaScript file within the container.

Sample Files

The samples/ folder contains various example files demonstrating different SDK functionalities:

Upload Examples

  • upload_client_credentials.js - Upload a new asset
  • upload_version_client_credentials.js - Upload a new version to an existing asset (uses data.mediaId)
  • upload_additional_client_credentials.js - Upload an additional file to an existing asset (uses additional: true and data.id)

QA - Run in Docker Container

# Build the image (only needed once or after code changes outside samples/ and secret.json)
docker build -t jssdk .

# Run a sample with local samples/ and secret.json mounted into the container
docker run --rm \
  --network=host \
  -v $(pwd)/samples:/app/samples \
  -v $(pwd)/secret.json:/app/secret.json \
  jssdk node samples/tags_client_credentials.js

版本与发布记录

@bynder/bynder-js-sdk 共发布 35 个版本,首次发布于 2017/06/08;过去 12 个月发布了 6 个版本。

版本发布日期距今
2.5.8latest2026/09/141 个月前
2.5.72026/08/182 个月前
2.5.62026/06/304 个月前
2.5.52026/06/254 个月前
2.5.42026/05/215 个月前
2.5.32026/05/086 个月前

关于 @bynder/bynder-js-sdk 的常见问题

@bynder/bynder-js-sdk 是什么?

Bynder Javascript SDK

如何安装 @bynder/bynder-js-sdk?

在项目目录运行 npm install @bynder/bynder-js-sdk,或使用 pnpm add / yarn add / bun add。

@bynder/bynder-js-sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bynder__bynder-js-sdk 是否存在。

@bynder/bynder-js-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bynder/bynder-js-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bynder/bynder-js-sdk 可以商用吗?

@bynder/bynder-js-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bynder/bynder-js-sdk 的下载量有多少?

根据 npm 官方下载统计,@bynder/bynder-js-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 75,344 次,日均约 2,511 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bynder/bynder-js-sdk 还在维护吗?

最新版本 2.5.8 发布于 2026/09/14(1 个月前);至今共发布 35 个版本,其中过去 12 个月发布了 6 个;首次发布于 2017/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。