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.
To use this SDK, you will need:
Node installation will include NPM, which is responsible for dependency management.
npm install @bynder/bynder-js-sdk
import Bynder from '@bynder/bynder-js-sdk';
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:
- Call the constructor with your configuration
const bynder = new Bynder({
baseURL: "https://portal.getbynder.com/",
clientId: "<your OAuth2 client id>",
clientSecret: "<your OAuth2 client secret>",
// A redirect URI is required for authorization codes, not client credentials
redirectUri: "<url where user will be redirected after authenticating>",
});
Make sure the
baseURL
does not have the/api
namespace at the end. The SDK will take care of it for you. Permanent tokens are no longer supported. Please request either an authorization code or client credentials.
- Create an authorization URL, login and get one-time authorization code
const authorizationURL = bynder.makeAuthorizationURL();
- 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: "https://api-url.bynder.io/",
clientId: "<your OAuth2 client id>",
clientSecret: "<your OAuth2 client secret>",
redirectUri: "<url where user will be redirected after authenticating>",
token: {
access_token: "<OAuth2 access token>"
}
});
You can now use the various methods from the SDK to fetch media, metaproperties
and other data. All methods return a promise, so 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
});
makeAuthorizationURL()
getToken()
userLogin(queryObject)
getMediaList(queryObject)
getMediaInfo(queryObject)
getAllMediaItems(queryObject)
getMediaTotal(queryObject)
editMedia(object)
deleteMedia(id)
getMediaDownloadUrl(queryObject)
getAssetUsage(queryObject)
saveNewAssetUsage(queryObject)
deleteAssetUsage(queryObject)
getMetaproperties(queryObject)
getMetaproperty(queryObject)
saveNewMetaproperty(object)
editMetaproperty(object)
deleteMetaproperty(object)
saveNewMetapropertyOption(object)
editMetapropertyOption(object)
deleteMetapropertyOption(object)
getMetapropertyOptions(queryObject)
getCollections(queryObject)
getCollection(queryObject)
saveNewCollection(queryObject)
shareCollection(queryObject)
addMediaToCollection(queryObject)
deleteMediaFromCollection(queryObject)
getTags(queryObject)
getSmartfilters(queryObject)
getBrands()
uploadFile(fileObject)
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:
- Clone the repository
- In the root folder, run
npm install
to install all of the dependencies. - Create a
secret.json
file with the following structure:
{
"baseURL": "https://api-url.bynder.io/",
"clientId": "<your OAuth2 client id>",
"clientSecret": "<your OAuth2 client secret>",
"redirectUri": "<url where user will be redirected after authenticating>"
}
- The following gulp tasks are available:
npm run lint
- Run ESlint and check the code.npm run build
- Run webpack to bundle the code in order to run in a browser.npm run doc
- Run JSDoc to create a 'doc' folder with automatically generated documentation for the source code.npm run dev
- Starts a builder in watch mode for development