Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shutterstock-api

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shutterstock-api

The Shutterstock API provides access to Shutterstock's library of media as well as information about customers accounts and the contributors that provide the media

  • 1.0.8
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
increased by68.98%
Maintainers
1
Weekly downloads
 
Created
Source

Official JavaScript SDK client for the Shutterstock API

The Shutterstock public API provides access to Shutterstock's library of media, as well as information about customers' accounts and the contributors that provide the media. This SDK provides classes for JavaScript and Node.js that you can use to access the API from your applications. These classes call the API in the same way that direct REST calls do. You can use this SDK to search for media, get information about media and about collections, and (if your subscription permits) license and download media. This is the official SDK provided by Shutterstock for its API.

  • API version: 1.0.8

References

  • For more information about the Shutterstock public API, see https://developers.shutterstock.com/documentation.
  • For reference information about the endpoints that this SDK calls, see the API reference.
  • To provide feedback or bug reports about the API and this SDK, see https://api-feedback.shutterstock.com.
  • For the status of the API, see API status.
  • For the source code, see https://github.com/shutterstock/public-api-javascript-sdk.

Subscriptions

To access the API and license media with the SDK, you need an API subscription or a free API account.

API subscriptions are separate from the subscriptions that are available on shutterstock.com. You can use an API subscription to license and download media only with the API; API subscriptions don't work on shutterstock.com. To buy an API subscription or set up a free account, see the pricing page. If you have a subscription from shutterstock.com and want to use it with the API, contact us.

Applications

The REST API uses an access token or secret key that is tied to your account and to an application. This application represents the application, program, or computer commands that are accessing the API. To use the API, you must create an application at https://developers.shutterstock.com/applications and note the client ID and client secret. You use this client ID and client secret either to use the API directly with basic authentication or to request a token for OAuth authentication.

Installation

npm or yarn

To install the SDK as a module with npm or yarn, run one of the following commands:

npm install shutterstock-api --save
yarn add shutterstock-api

Authentication

Authentication in the SDK works the same way as in the API:

All endpoints in the Shutterstock API require authentication. The API accepts HTTP basic authentication for some endpoints and OAuth authentication for all endpoints.

In the reference information for each SDK method (see Documentation for methods or the API reference, each endpoint is labeled with the types of authentication it accepts and the OAuth scopes it requires, if any. In general, HTTP basic authentication is sufficient for search queries and for getting information about pieces of media. The API requires OAuth authentication for actions that require customers to log in to shutterstock.com, such as licensing and downloading media.

For more information about authenticating to the API, see Authentication in the API reference.

Basic authentication

In HTTP basic authentication (also known as basic authentication), you pass your application's client ID and secret key to the SDK along with the request. To get the client ID and secret key for your application, go to https://developers.shutterstock.com/user/me/apps and open the information for your application. The following example uses the variables applicationClientId and applicationClientSecret for the application's client ID and secret.

const sstk = require('shutterstock-api');

sstk.setBasicAuth(applicationClientId, applicationClientSecret);

const api = new sstk.ImagesApi();

OAuth authentication

In this type of authentication, you use an application and an individual user's login credentials to obtain a token. For instructions on how to get a token, see OAuth authentication on the Shutterstock developer portal.

When you have the token, use it to configure the API client as in the following example, using the token as the value of the myAccessToken variable:

const sstk = require('shutterstock-api');

sstk.setAccessToken(process.env.SHUTTERSTOCK_API_TOKEN);

const api = new sstk.ImagesApi();

OAuth scopes

Most endpoints require an access token with one or more scopes, or permissions. You can see the scopes that each method requires in the reference information for each method.

The following list shows the available scopes.

  • licenses.create: Grant the ability to download and license media on behalf of the user.
  • purchases.view: Grant read-only access to a user's purchase history.
  • licenses.view: Grant read-only access to a user's licenses.
  • collections.edit: Grant the ability to create new collections, edit a collection, and modify the contents of a collection
  • collections.view: Grant read-only access to a collection and its contents.
  • user.view: Grants read-only access to a user's basic account information (includes username, id, first and last name). If email is the same as username, it also implies user.email

Examples

Follow the installation instructions and use the SDK in your JavaScript code as in these examples.

This example searches for images. The search parameters go in the queryParams variable. The API returns responses as JavaScript objects. The reference information for each method shows the class for the response. In this example, the callback function extracts the image ID, description, and preview link of each search result into an object.

const sstk = require('shutterstock-api');

sstk.setAccessToken(process.env.SHUTTERSTOCK_API_TOKEN);

const api = new sstk.ImagesApi();

const queryParams = {
  query: 'New York',
  sort: 'popular',
  orientation: 'horizontal'
};

api.searchImages(queryParams)
  .then(({data}) => {
    console.log(data);
  })
  .catch((error) => {
    console.error(error);
  });

The next example requests a license for an image.

For POST requests like this one, you must create an object of the appropriate class to pass as the request body. In this case, the shutterstock-api.ImagesApi.licenseImages method accepts a body parameter of the class shutterstock-api.LicenseImageRequest. This parameter is an array of objects of the class shutterstock-api.LicenseImage, each of which has the ID of an image to license. The reference information for each method shows the class for the body parameter.

const sstk = require('shutterstock-api');

sstk.setAccessToken(process.env.SHUTTERSTOCK_API_TOKEN);

const api = new sstk.ImagesApi();

const imageId = '' // ID of image to license

const imageToLicense = new sstk.LicenseImage(imageId);

const body = new sstk.LicenseImageRequest([imageToLicense]);

const queryParams = {
  subscriptionId: process.env.SHUTTERSTOCK_SUBSCRIPTION_ID,
  format: 'jpg',
  size: 'huge'
};

api.licenseImages(body, queryParams)
  .then(({data}) => {
    console.log(data);
  })
  .catch((error) => {
    console.error(error);
  });

Contributing

Tests

To run the tests, you must authenticate with the Shutterstock API, get a token, and put the token in the SHUTTERSTOCK_API_TOKEN environment variable. See Authentication.

$ SHUTTERSTOCK_API_TOKEN="Your API Key"
$ yarn run test

Linting

$ yarn run lint

Documentation for methods

All URIs are relative to https://api.shutterstock.com

ClassMethodHTTP requestDescription
shutterstock-api.AudioApiaddSoundboxItemsPOST /v2/audio/collections/{id}/itemsAdd audio tracks to collections
shutterstock-api.AudioApicreateSoundboxPOST /v2/audio/collectionsCreate audio collections
shutterstock-api.AudioApideleteSoundboxDELETE /v2/audio/collections/{id}Delete audio collections
shutterstock-api.AudioApideleteSoundboxItemsDELETE /v2/audio/collections/{id}/itemsRemove audio tracks from collections
shutterstock-api.AudioApidownloadTracksPOST /v2/audio/licenses/{id}/downloadsDownload audio tracks
shutterstock-api.AudioApigetAudioLicenseListGET /v2/audio/licensesList audio licenses
shutterstock-api.AudioApigetSoundboxGET /v2/audio/collections/{id}Get the details of audio collections
shutterstock-api.AudioApigetSoundboxItemsGET /v2/audio/collections/{id}/itemsGet the contents of audio collections
shutterstock-api.AudioApigetSoundboxListGET /v2/audio/collectionsList audio collections
shutterstock-api.AudioApigetTrackGET /v2/audio/{id}Get details about audio tracks
shutterstock-api.AudioApigetTrackListGET /v2/audioList audio tracks
shutterstock-api.AudioApilicenseTrackPOST /v2/audio/licensesLicense audio tracks
shutterstock-api.AudioApirenameSoundboxPOST /v2/audio/collections/{id}Rename audio collections
shutterstock-api.AudioApisearchAudioGET /v2/audio/searchSearch for tracks
shutterstock-api.ContributorsApigetContributorGET /v2/contributors/{contributor_id}Get details about a single contributor
shutterstock-api.ContributorsApigetContributorCollectionItemsGET /v2/contributors/{contributor_id}/collections/{id}/itemsGet the items in contributors' collections
shutterstock-api.ContributorsApigetContributorCollectionsGET /v2/contributors/{contributor_id}/collections/{id}Get details about contributors' collections
shutterstock-api.ContributorsApigetContributorCollectionsListGET /v2/contributors/{contributor_id}/collectionsList contributors' collections
shutterstock-api.ContributorsApigetContributorListGET /v2/contributorsGet details about multiple contributors
shutterstock-api.EditorialApigetEditorialImageGET /v2/editorial/{id}Get editorial content details
shutterstock-api.EditorialApigetEditorialLivefeedGET /v2/editorial/livefeeds/{id}Get editorial livefeed
shutterstock-api.EditorialApigetEditorialLivefeedItemsGET /v2/editorial/livefeeds/{id}/itemsGet editorial livefeed items
shutterstock-api.EditorialApigetEditorialLivefeedListGET /v2/editorial/livefeedsGet editorial livefeed list
shutterstock-api.EditorialApilicenseEditorialImagePOST /v2/editorial/licensesLicense editorial content
shutterstock-api.EditorialApisearchEditorialGET /v2/editorial/searchSearch editorial content
shutterstock-api.ImagesApiaddLightboxItemsPOST /v2/images/collections/{id}/itemsAdd images to collections
shutterstock-api.ImagesApicreateLightboxPOST /v2/images/collectionsCreate image collections
shutterstock-api.ImagesApideleteLightboxDELETE /v2/images/collections/{id}Delete image collections
shutterstock-api.ImagesApideleteLightboxItemsDELETE /v2/images/collections/{id}/itemsRemove images from collections
shutterstock-api.ImagesApidownloadImagePOST /v2/images/licenses/{id}/downloadsDownload images
shutterstock-api.ImagesApigetFeaturedLightboxGET /v2/images/collections/featured/{id}Get the details of featured image collections
shutterstock-api.ImagesApigetFeaturedLightboxItemsGET /v2/images/collections/featured/{id}/itemsGet the contents of featured image collections
shutterstock-api.ImagesApigetFeaturedLightboxListGET /v2/images/collections/featuredList featured image collections
shutterstock-api.ImagesApigetImageGET /v2/images/{id}Get details about images
shutterstock-api.ImagesApigetImageCategoriesGET /v2/images/categoriesList image categories
shutterstock-api.ImagesApigetImageLicenseListGET /v2/images/licensesList image licenses
shutterstock-api.ImagesApigetImageListGET /v2/imagesList images
shutterstock-api.ImagesApigetImageRecommendationsGET /v2/images/recommendationsList recommended images
shutterstock-api.ImagesApigetLightboxGET /v2/images/collections/{id}Get the details of image collections
shutterstock-api.ImagesApigetLightboxItemsGET /v2/images/collections/{id}/itemsGet the contents of image collections
shutterstock-api.ImagesApigetLightboxListGET /v2/images/collectionsList image collections
shutterstock-api.ImagesApigetSimilarImagesGET /v2/images/{id}/similarList similar images
shutterstock-api.ImagesApigetUpdatedImagesGET /v2/images/updatedList updated images
shutterstock-api.ImagesApilicenseImagesPOST /v2/images/licensesLicense images
shutterstock-api.ImagesApirenameLightboxPOST /v2/images/collections/{id}Rename image collections
shutterstock-api.ImagesApisearchImagesGET /v2/images/searchSearch for images
shutterstock-api.ImagesApiuploadEphemeralImagePOST /v2/imagesUpload images
shutterstock-api.TestApiechoGET /v2/testEcho text
shutterstock-api.TestApivalidateGET /v2/test/validateValidate input
shutterstock-api.UsersApicreateUserPOST /v2/userRegister user
shutterstock-api.UsersApigetAccessTokenGET /v2/user/access_tokenGet access token details
shutterstock-api.UsersApigetUserGET /v2/userGet user details
shutterstock-api.UsersApigetUserSubsciptionListGET /v2/user/subscriptionsList user subscriptions
shutterstock-api.VideosApiaddClipboxItemsPOST /v2/videos/collections/{id}/itemsAdd videos to collections
shutterstock-api.VideosApicreateClipboxPOST /v2/videos/collectionsCreate video collections
shutterstock-api.VideosApideleteClipboxDELETE /v2/videos/collections/{id}Delete video collections
shutterstock-api.VideosApideleteClipboxItemsDELETE /v2/videos/collections/{id}/itemsRemove videos from collections
shutterstock-api.VideosApidownloadVideosPOST /v2/videos/licenses/{id}/downloadsDownload videos
shutterstock-api.VideosApigetClipboxGET /v2/videos/collections/{id}Get the details of video collections
shutterstock-api.VideosApigetClipboxItemsGET /v2/videos/collections/{id}/itemsGet the contents of video collections
shutterstock-api.VideosApigetClipboxListGET /v2/videos/collectionsList video collections
shutterstock-api.VideosApigetSimilarVideosGET /v2/videos/{id}/similarList similar videos
shutterstock-api.VideosApigetUpdatedVideosGET /v2/videos/updatedList updated videos
shutterstock-api.VideosApigetVideoGET /v2/videos/{id}Get details about videos
shutterstock-api.VideosApigetVideoCategoriesGET /v2/videos/categoriesList video categories
shutterstock-api.VideosApigetVideoLicenseListGET /v2/videos/licensesList video licenses
shutterstock-api.VideosApigetVideoListGET /v2/videosList videos
shutterstock-api.VideosApilicenseVideosPOST /v2/videos/licensesLicense videos
shutterstock-api.VideosApirenameClipboxPOST /v2/videos/collections/{id}Rename video collections
shutterstock-api.VideosApisearchVideosGET /v2/videos/searchSearch for videos

FAQs

Package last updated on 19 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc