WrapSplashTS is a simple, promise-based API wrapper for the popular Unsplash platform. The library is now written in TypeScript, bundled with Vite, and can be used in both Node.js and browser-based projects. Unsplash provides beautiful high quality free images and photos that you can download and use for any project without any attribution.
Before using the Unsplash API, you need to register as a developer and read the API Guidelines.
Note: Every application must abide by the API Guidelines. Specifically, remember to hotlink images and trigger a download when appropriate.
- About
- Installation
- Sample Usage
- Development
- New API aliases
- Dependency
- Changelog
- API Documentation
- Schema
- Authorization
- Users APIs
- Photos APIs
- Search APIs
- Current User APIs
- Stats APIs
- Collections APIs
- Link Relations
- List Collections
- List Featured Collections
- List Curated Collections
- Get a Collection
- Get a Curated Collection
- Get a Collection's Photos
- Get a Curated Collection's Photos
- List a Collection’s Related Collections
- Create a New Collection
- Update an Existing Ccollection
- Delete a Collection
- Add a Photo to a Collection
- Remove a Photo from a Collection
- Continuous Integration (CI)
- Tests
- License
- Acknowledgements
Install the package from NPM
npm install --save wrapsplashThe package exposes the main class through ES module and CommonJS entry points configured via the exports field in package.json.
// CommonJS
const WrapSplash = require('wrapsplash');
// ES modules
import WrapSplash from 'wrapsplash';
const unsplash = new WrapSplash();
unsplash.init({
bearer_token: '<bearer-token>',
});
unsplash.getPhoto('<photo-id>')
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});npm install
npm run build
npm test
npm run test:coverage # Generate coverage report
npm run lintThe package also includes a prepublish validation step that runs the build and tests before release.
This project uses Vitest with V8 coverage provider to track test coverage. Coverage reports are automatically generated and uploaded to Codecov on every push to main or master branches via GitHub Actions CI.
View the latest coverage report:
To generate a local coverage report:
npm run test:coverage
# Coverage report will be generated in ./coverage directory| Metric | Coverage | Threshold |
|---|---|---|
| Statements | 97.8% | 80% |
| Branches | 79.5% | 55% |
| Functions | 98.4% | 80% |
| Lines | 97.8% | 80% |
Coverage thresholds (enforced):
- Lines: 80%
- Functions: 80%
- Branches: 55%
- Statements: 80%
The library now includes more descriptive convenience methods such as getPhoto, getRandomPhoto, createCollection, and updateCollection. The original method names remain available for backward compatibility.
The legacy method createNewColection (with misspelled "Colection") has been superseded by the correctly-spelled createNewCollection. The old method remains available as a deprecated alias for backward compatibility, but new code should use createNewCollection.
// Legacy (deprecated, but still works)
unsplash.createNewColection('My Collection');
// Recommended (new, correct spelling)
unsplash.createNewCollection('My Collection');200 OK{
"url": "https://images.unsplash.com/photo-1532800621406-0280a106eaa6?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&s=70d0f9f241b88d82c7d0e52b93476e6a"
}This library depends on axios to make requests and generates required request headers for the Unsplash API.
- Security: Removed
crypto-jsdependency (CVE-2023-46233), replaced with Node.js built-incryptomodule - Added
filesfield topackage.jsonto prevent publishing unnecessary files to npm - Added smart retry logic with exponential backoff and
Retry-Afterheader support - Added retryable error filtering: only network errors, timeouts, 429, and 5xx responses are retried
- Removed stale root
index.jsentry point in favor ofpackage.jsonexports configuration - Removed
crypto-jsand@types/crypto-jsfrom dependencies - Updated Security Policy: 5.0.x is now a supported version
- Updated PR template to reference GitHub Actions instead of Travis/Circle CI
- Expanded test suite from 32 to 109 tests with 97.8% statement coverage
- Rebranded project name from WrapSplashJS to WrapSplashTS to reflect TypeScript-first development
- Fixed missing type definitions for
WrapSplashResponseandWrapSplashErrorclass - Updated Vite from 6.4.2 to 8.1.5 resolving security vulnerabilities in esbuild dependency
- Updated TypeScript configuration: changed
moduleResolutionfrom deprecated "node" to "bundler" standard - Enhanced type safety with explicit
WrapSplashResponsetype for all API methods - Improved error handling with
WrapSplashErrorclass providingstatusCode,statusText, andcauseproperties - Integrated Codecov for automated code coverage tracking via GitHub Actions
- Added V8 coverage provider with multiple output formats (text, LCOV, JSON, HTML)
- Enforced coverage thresholds: 80% lines/functions/statements, 55% branches
- Added clearer convenience methods such as
getPhoto,getRandomPhoto,createCollection, andupdateCollection - Preserved backward compatibility for the existing method names while introducing the newer API surface
- Improved input validation for required parameters and unsupported option values
- Added configurable request timeout support for network requests
- Added ESLint configuration and a GitHub Actions CI workflow for automated build and test checks
- Expanded regression coverage for the new aliases and validation behavior
- Deprecation: The legacy method
createNewColection(misspelled) is now deprecated; usecreateNewCollectioninstead (both methods remain functional for backward compatibility)
- Bumped package version for npm release
- Updated README version and changelog entries
- Fixed example entrypoint and constructor usage
- Migrated source to TypeScript
- Switched bundler from Webpack to Vite
- Updated tests to Vitest-compatible configuration
- Dependency vulnerabilities audited and fixed
- Typos fixed
- Dependency vulnerabilities audited and fixed
- Major refactorings
- Updated documentation
- Dependency updates
- Library is now a UMD module, runs on client and server-side
- Dependencies are now external
- Compressed builds asset size reduced to 19KiB
- AJAX migrated to Axios from fetch.
- Tests migrated to Jest
- Compressed builds available
- Asset size reduced to 30.7KiB
- Updated Documentation
- Updated dependencies
- Code Quality improved
- Dependency security aduits enabled
- Updated Documentation
- Updated dependecies
- Updated dependecies
- Minor bug fix.
- Minor security fixes.
- Minor bug fixes.
- Code cleanups.
- Updated documentations.
- Test environment setup using Mochajs.
- Assertion test specs added using Chaijs.
- Strict server response validations added.
- Completely re-written in
ES6&ES7specifications. - Continuous Integrations (CI) using modern Node.js workflows.
- Minor bug fixes.
- Major code optimizations.
- Updated documentaions.
- Major refactorings.
- Now supports Yarn package manager
https://yarnpkg.com/en/package/wrapsplash.
- Now available at major CDNs:
- unpkg -
https://unpkg.com/wrapsplash@3.0.0/. - bundle.run -
https://bundle.run/wrapsplash@3.0.0. - jsDelivr -
https://cdn.jsdelivr.net/npm/wrapsplash@3.0.0/.
- unpkg -
- Minor bug fix.
- Documentation updated.
- Added support for Collections APIs.
- Get a single page from the list of all collections -
GET /collections. - Get a single page from the list of featured collections -
GET /collections/featured. - Get a single page from the list of curated collections -
GET /collections/curated. - Retrieve a single collection -
GET /collections/:id. - Retrieve a curated collection -
GET /collections/curated/:id. - Retrieve a collection’s photos -
GET /collections/:id/photos. - Retrieve a curated collection’s photos -
GET /collections/curated/:id/photos. - Retrieve a list of collections -
GET /collections/:id/related. - Create a new collection -
POST /collections. - Update an existing collection belonging to the logged-in user -
PUT /collections/:id. - Delete a collection belonging to the logged-in user -
DELETE /collections/:id. - Add a photo to one of the logged-in user’s collections -
POST /collections/:collection_id/add. - Remove a photo from one of the logged-in user’s collections -
DELETE /collections/:collection_id/remove.
- Get a single page from the list of all collections -
- Added support for Current User APIs
- Get the user’s profile -
GET /me. - Update the current user’s profile -
PUT /me.
- Get the user’s profile -
- Added support for Stats APIs
- Get a list of counts for all of Unsplash -
GET /stats/total. - Get the overall Unsplash stats for the past 30 days -
GET /stats/month.
- Get a list of counts for all of Unsplash -
- Major refactorings.
- Documentation updated.
- Added support for Authorization.
- Added support for Bearer Token.
- Added support for private data Read Write Access.
- Added support for full Photos APIs
- Get a single page from the list of all photos -
GET /photos. - Get a single page from the list of the curated photos -
GET /photos/curated. - Retrieve a single photo -
GET /photos/:id. - Retrieve a single random photo, given optional filters -
GET /photos/random. - Retrieve statistics of a photo in a specific timeframe -
GET /photos/:id/statistics. - Retrieve a single photo’s download link -
GET /photos/:id/download. - Update a photo on behalf of the logged-in user -
PUT /photos/:id. - Like a photo on behalf of the logged-in user -
POST /photos/:id/like. - Remove a user’s like of a photo -
DELETE /photos/:id/like.
- Get a single page from the list of all photos -
- Major refactorings.
- Documentation patch.
- Now supports full Search APIs.
- Added support for new API endpoints.
- Get a single page of photo results for a query -
GET /search/photos. - Get a single page of collection results for a query -
GET /search/collections. - Get a single page of user results for a query -
GET /search/users.
- Get a single page of photo results for a query -
- Now supports full Users APIs.
- Added support for new API endpoints.
- Get a list of collections created by the user -
GET /users/:username/collections. - Get a user's account statistics -
GET /users/:username/statistics.
- Get a list of collections created by the user -
- Major refactorings.
- Added support for new API endpoint.
- Get a list of photos liked by a user -
GET /users/:username/likes.
- Get a list of photos liked by a user -
- Minor refactorings.
The API we are using is https://api.unsplash.com/. Responses are sent as JSON.
When retrieving a list of objects, an abbreviated or summary version of that object is returned - i.e., a subset of its attributes. To get a full detailed version of that object, fetch it individually.
If an error occurs, whether on the server or client side, the error message(s) will be returned in an errors array.
For example:
422 Unprocessable Entity{
"errors": ["Username is missing", "Password cannot be blank"]
}Many actions can be performed without requiring authentication from a specific user. For example, downloading a photo does not require a user to log in.
To authenticate requests in this way, pass your application’s access key via the HTTP Authorization header:
Authorization: Client-ID YOUR_ACCESS_KEYYou can also pass this value using a client_id query parameter:
https://api.unsplash.com/photos/?client_id=YOUR_ACCESS_KEYIf only your access key is sent, attempting to perform non-public actions that require user authorization will result in a 401 Unauthorized response.
The Unsplash API uses OAuth2 to authenticate and authorize Unsplash users. Unsplash’s OAuth2 paths live at https://unsplash.com/oauth/.
Before using wrapsplash:
- Developers are required to create a developer account from Unsplash.
- Create a new App from Your Apps page.
- Get the
Access Key,Secret key,Callback URLs, andAuthorization code. - If you have a Bearer Token, then its super, or else you can generate it using wrapsplash.
Note:
Authorization codecan be obtained by clicking theAuthorizelink next toCallback URLs. AlsoAuthorization codeis a one-time use code, you have to generate it again, if the action fails!.
Wrapsplash instance has to be initialized with your credentials obtained from Unsplash developer account for programatic access.These credentials information are passed in to the init() function as options. The following example shows all the available options.
UnsplashApi.init({
access_key: '<api-key>',
secret_key: '<secret-key>',
redirect_uri: '<callback-url>',
code: '<authorization-code>',
bearer_token: '<bearer-token>'
});If you have a bearer_token, then only bearer token has to be passed in.
UnsplashApi.init({
bearer_token: '<bearer-token>'
});A Promise factory to generate a Bearer Token for write_access to private data.
The init() method in this case requires access_key, secret_key, redirect_uri, and code to generate bearer token.
Note: No Parameters are required for this function.
const WrapSplash = require('wrapsplash');
let UnsplashApi = new WrapSplash();
UnsplashApi.init({
access_key: '<api-key>',
secret_key: '<secret-key>',
redirect_uri: '<callback-url>',
code: '<authorization-code>',
});
UnsplashApi.generateBearerToken()
.then(function (result) {
console.log(result);
}).catch(function (e) {
console.err(e);
});If successful, the response body will be a JSON representation of your user’s access token a.k.a bearer token:
{
"access_token": "091343ce13c8ae780065ecb3b13dc903475dd22cb78a05503c2e0c69c5e98044",
"token_type": "bearer",
"scope": "public read_photos write_photos",
"created_at": 1436544465
}and once you have your bearer_token you can use it in your app like this:
UnsplashApi.init({
bearer_token: '<bearer-token>'
});A Promise factory to retrieve public details on a given user.
GET /users/:username
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no | |
| width | number | Width of the profile picture in pixels | yes | |
| height | number | Height of the profile picture in pixels | yes |
Note: When optional height & width are specified the profile image will be included in the "profile_image" object as "custom".
UnsplashApi.getPublicProfile('<username>', 600, 600);A Promise factory to retrieve a single user’s portfolio link.
GET /users/:username/portfolio
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no |
UnsplashApi.getUserPortfolio('<username>');A Promise factory to get a list of photos uploaded by a particular user.
GET /users/:username/photos
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
| stats | boolean | Show the stats for each user’s photo | yes | false |
| resolution | string | The frequency of the stats | yes | days |
| quantity | number | The amount of for each stat | yes | 30 |
| order_by | string | How to sort the photos.(Valid values: latest, oldest, popular) |
yes | latest |
UnsplashApi.getUserPhotos('<username>', 1, 10, false, 'days', 30, 'latest');A Promise factory to get a list of photos liked by a user.
GET /users/:username/likes
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
| order_by | string | How to sort the photos.(Valid values: latest, oldest, popular) |
yes | latest |
UnsplashApi.getUserLikedPhotos('<username>', 1, 10, 'latest');A Promise factory to get a list of collections created by the user.
GET /users/:username/collections
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.getUserCollections('<username>', 1, 10);A Promise factory to get a user's account statistics.
GET /users/:username/statistics
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | string | The username of the particular user | no | |
| resolution | string | The frequency of the stats | yes | days |
| quantity | number | The amount of for each stat | yes | 30 |
UnsplashApi.getUserStatistics('<username>', 'days', 30);A Promise factory to get a single page from the list of all photos.
GET /photos
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
| order_by | string | How to sort the photos.(Valid values: latest, oldest, popular) |
yes | latest |
UnsplashApi.listPhotos(1, 10, 'latest');A Promise factory to get a single page from the list of the curated photos.
GET /photos/curated
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
| order_by | string | How to sort the photos.(Valid values: latest, oldest, popular) |
yes | latest |
UnsplashApi.listCuratedPhotos(1, 10, 'latest');A Promise factory to retrieve a single photo.
GET /photos/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no | |
| width | number | Image width in pixels | yes | |
| height | number | Image height in pixels | yes | |
| rect | string | 4 comma-separated integers representing x, y, width, height of the cropped rectangle | yes |
Note: Supplying the optional width or height parameters will result in the custom photo URL being added to the urls object:
UnsplashApi.getAPhoto('<id of the photo>', 500, 500, 'x, y, width, height');A Promise factory to retrieve a single random photo, given optional filters.
GET /photos/random
Note: All parameters are optional, and can be combined to narrow the pool of photos from which a random one will be chosen.
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| collection | String | The public collection ID(‘s) to filter selection. If multiple, comma-separated | yes | |
| featured | Boolean | Limit selection to featured photos | yes | false |
| username | String | Limit selection to a single user | yes | |
| query | String | Limit selection to photos matching a search term | yes | |
| width | Number | The Image width in pixels | yes | |
| height | Number | The Image height in pixels | yes | |
| orientation | String | Filter search results by photo orientation. (Valid values are landscape, portrait, and squarish) |
yes | landscape |
| count | Number | The number of photos to return. (max: 30) |
yes | 1 |
Note: You can’t use the collections and query parameters in the same request. When supplying a count parameter - and only then - the response will be an array of photos, even if the value of count is 1.
UnsplashApi.getARandomPhoto();A Promise factory to retrieve total number of downloads, views and likes of a single photo, as well as the historical breakdown of these stats in a specific timeframe (default is 30 days).
GET /photos/:id/statistics
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no | |
| resolution | string | The frequency of the stats | yes | days |
| quantity | number | The amount of for each stat | yes | 30 |
Note: Currently, the only resolution param supported is “days”. The quantity param can be any number between 1 and 30.
UnsplashApi.getPhotoStatistics('<photo-id>', 'days', 10);A Promise factory to retrieve a single photo’s download link. Preferably hit this endpoint if a photo is downloaded in your application for use (example: to be displayed on a blog article, to be shared on social media, to be remixed, etc).
GET /photos/:id/download
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no |
Note: This is different than the concept of a view, which is tracked automatically when you hotlink an image.
UnsplashApi.getPhotoLink('<photo-id>');A Promise factory to update a photo on behalf of the logged-in user. This requires the write_photos scope and bearer_token.
PUT /photos/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no | |
| location | object | The location object holding location data | yes | |
| exif | object | The exif object holding exif data | yes |
Note: Exchangeable image file format (officially Exif, according to JEIDA/JEITA/CIPA specifications) is a standard that specifies the formats for images, sound, and ancillary tags used by digital cameras (including smartphones), scanners and other systems handling image and sound files recorded by digital cameras. Readmore
| object[key] | Description |
|---|---|
| location[latitude] | The photo location’s latitude (Optional) |
| location[longitude] | The photo location’s longitude (Optional) |
| location[name] | The photo location’s name (Optional) |
| location[city] | The photo location’s city (Optional) |
| location[country] | The photo location’s country (Optional) |
| location[confidential] | The photo location’s confidentiality (Optional) |
| exif[make] | Camera’s brand (Optional) |
| exif[model] | Camera’s model (Optional) |
| exif[exposure_time] | Camera’s exposure time (Optional) |
| exif[aperture_value] | Camera’s aperture value (Optional) |
| exif[focal_length] | Camera’s focal length (Optional) |
| exif[iso_speed_ratings] | Camera’s iso (Optional) |
UnsplashApi.updatePhoto('<photo-id>', {country: 'INDIA'}, {make: 'Redmi Note 3'});A Promise factory to like a photo on behalf of the logged-in user. This requires the write_likes scope.
POST /photos/:id/like
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no |
Note: This action is idempotent; sending the POST request to a single photo multiple times has no additional effect.
UnsplashApi.likePhoto('<photo-id>');A Promise factory to remove a user’s like of a photo.
DELETE /photos/:id/like
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The photo’s ID | no |
Note: This action is idempotent; sending the DELETE request to a single photo multiple times has no additional effect.
UnsplashApi.unlikePhoto('<photo-id>');A Promise factory to get a single page of photo results for a particular query.
GET /search/photos
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| query | string | The search query | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
| collections | number | Collection ID(‘s) to narrow search. If multiple, comma-separated. | yes | |
| orientation | string | Filter search results by photo orientation. (Valid values are landscape, portrait, and squarish.) |
yes | landscape |
UnsplashApi.search('cars', 1, 10, '', 'landscape');A Promise factory to get a single page of collection results for a query.
GET /search/collections
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| query | string | The search query | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.searchCollections('cars', 1, 10);A Promise factory to get a single page of user results for a query.
GET /search/users
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| query | string | The search query | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.searchUsers('<search-keyword>', 1, 10);A Promise factory to get the current User's profile. To access a user’s private data, the user is required to authorize the read_user scope. Without it, this request will return a 403 Forbidden response.
GET /me
Note: No Parameters are required.
Note: Without a Bearer token (i.e. using a
Client-ID token) this request will return a401 Unauthorizedresponse.
UnsplashApi.getCurrentUserProfile();A Promise factory to update the current User's profile.
PUT /me
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| username | String | The username of the current user | yes | |
| first_name | String | The first name of the current user | yes | |
| last_name | String | The last name of the current user | yes | |
| String | The email id of the current user | yes | ||
| url | String | The Portfolio/personal URL of the current user | yes | |
| location | String | The location of the current user | yes | |
| bio | String | The About/bio of the current user | yes | |
| instagram_username | String | The Instagram username of the current user | yes |
Note: This action requires the
write_user scope. Without it, it will return a403 Forbidden response.
UnsplashApi.updateCurrentUserProfile('<username>', '<first_name>', '<last_name>', '<email>', '<url>', '<location>', '<bio>', '<instagram_username>');A Promise factory to get a list of counts for all of Unsplash.
GET /stats/total
UnsplashApi.getStatsTotals();200 OK{
total_stats = {
"photos" => 10000,
"downloads" => 2000,
"views" => 5000,
"likes" => 800,
"photographers" => 100,
"pixels" => 200000,
"downloads_per_second" => 10, // average number of downloads per second for the past 7 days
"views_per_second" => 20, // average number of views per second for the past 7 days
"developers" => 20,
"applications" => 50,
"requests" => 8000
}
}A Promise factory to get the overall Unsplash stats for the past 30 days.
GET /stats/month
UnsplashApi.getStatsMonth();200 OK{
month_stats = {
"downloads" => 20,
"views" => 200,
"likes" => 60,
"new_photos" => 10,
"new_photographers" => 5,
"new_pixels" => 2000,
"new_developers" => 8,
"new_applications" => 5,
"new_requests" => 100
}
}Collections have the following link relations:
| rel | Description |
|---|---|
self |
API location of this collection |
html |
HTML location of this collection |
photos |
API location of this collection’s photos |
related |
API location of this collection’s related collections (Non-curated collections only) |
download |
Download location of this collection’s zip file (Curated collections only) |
A Promise factory to get a single page from the list of all collections.
GET /collections
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.listCollections();A Promise factory to get a single page from the list of featured collections.
GET /collections/featured
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.listFeaturedCollections();A Promise factory to get a single page from the list of curated collections.
GET /collections/curated
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.listCuratedCollections();A Promise factory to retrieve a single collection. To view a user’s private collections, the read_collections scope is required.
GET /collections/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no |
UnsplashApi.getCollection('<collection-id>');A Promise factory to retrieve a single curated collection. To view a user’s private collections, the read_collections scope is required.
GET /collections/curated/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no |
UnsplashApi.getCuratedCollection('<curated-collection-id>');A Promise factory to retrieve a collection’s photos.
GET /collections/:id/photos
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.getCollectionPhotos('<collection-id>', 1, 10);A Promise factory to retrieve a curated collection’s photos.
GET /collections/curated/:id/photos
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no | |
| page | number | Page number to retrieve | yes | 1 |
| per_page | number | Number of items per page | yes | 10 |
UnsplashApi.getCuratedCollectionPhotos('<curated-collection-id>', 1, 10);A Promise factory to retrieve a list of collections related to this one.
GET /collections/:id/related
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no |
UnsplashApi.listRelatedCollections('<collection-id>');A Promise factory to create a new collection. This requires the write_collections scope.
POST /collections
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| title | string | The title of the collection | no | |
| description | string | The collection’s description | yes | |
| private | boolean | Whether to make this collection private | yes | false |
UnsplashApi.createNewCollection('<collection-name>', '<description>', false);A Promise factory to update an existing collection belonging to the logged-in user. This requires the write_collections scope.
PUT /collections/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The collection id | no | |
| title | string | The title of the collection | yes | |
| description | string | The collection’s description | yes | |
| private | boolean | Whether to make this collection private | yes | false |
UnsplashApi.updateExistingCollection('<collection-id>','<collection-name>', '<description>', false);A Promise factory to delete a collection belonging to the logged-in user. This requires the write_collections scope.
DELETE /collections/:id
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| id | string | The Collection ID | no |
UnsplashApi.deleteCollection('<collection-id>');A Promise factory to add a photo to one of the logged-in user’s collections. Requires the write_collections scope.
POST /collections/:collection_id/add
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| collection_id | string | The Collection ID | no | |
| photo_id | string | The Photo ID | no |
Note: If the photo is already in the collection, this acion has no effect.
UnsplashApi.addPhotoToCollection('<collection-id>', '<photo-id>');A Promise factory to remove a photo from one of the logged-in user’s collections. Requires the write_collections scope.
DELETE /collections/:collection_id/remove
| Parameter | Type | Description | Optional | Default |
|---|---|---|---|---|
| collection_id | string | The Collection ID | no | |
| photo_id | string | The Photo ID | no |
UnsplashApi.removePhotoFromCollection('<collection-id>', '<photo-id>');This project uses Vite for bundling and Vitest for testing. In CI, run:
npm install
npm run build
npm testA minimal GitHub Actions workflow can use the same commands in a standard Node.js environment.
WrapSplashTS uses Vitest as the testing environment. Test files are available in the test/ folder.
The MIT License
Copyright (c) 2018- Sandeep Vattapparambil, http://www.sandeepv.in
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Thanks, and Kudos to team Unsplash for creating a wonderful platform for sharing beautiful high quality free images and photos.
Made with ❤️ by Sandeep Vattapparambil.

