Bynder / bynder-js-sdk

SDK in JavaScript (Node.js) for integration with Bynder
MIT License
33 stars 41 forks source link
api integration javascript sdk

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>"
});

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

Media

Media usage

Metaproperties

Collections

Tags

Smartfilters

Brands

Upload

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: