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

unsplash-js

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unsplash-js - npm Package Compare versions

Comparing version 6.3.0 to 7.0.0-beta.1

dist/beacon.d.ts

130

CHANGELOG.md
# Changelog
## 7.0.0
This version includes a total TypeScript rewrite of the library, with many breaking changes. If upgrading from a previous version, read carefully. You will not be able to upgrade to v7 without making the necessary adjustments.
### Breaking Changes
- Replaces the `Unsplash` `class` with a named `createApi` function:
```ts
// before
import Unsplash from 'unsplash-js';
const unsplash = new Unsplash({ accessKey: 'MY_ACCESS_KEY' });
// after
import { createApi } from 'unsplash-js';
const unsplash = createApi({ accessKey: 'MY_ACCESS_KEY' });
// or
import Unsplash from 'unsplash-js';
const unsplash = Unsplash.createApi({ accessKey: 'MY_ACCESS_KEY' });
```
- Removes user authentication features from the library. This means that the `createApi` function does not recieve `secret`, `callbackUrl` or `bearerToken`.
* Removes the following API methods (primarily due to removal of user authentication):
- `photos`:
- ❌ `likePhoto`
- ❌ `unlikePhoto`
- ❌ `downloadPhoto` (deprecated in 6.3, replaced with `trackDownload`)
- `users`:
- ❌ `statistics`
- `collections`:
- ❌ `createCollection`
- ❌ `updateCollection`
- ❌ `deleteCollection`
- ❌ `addPhotoToCollection`
- ❌ `removePhotoFromCollection`
- `auth`:
- ❌ `getAuthenticationUrl`
- ❌ `userAuthentication`
- ❌ `setBearerToken`
- `currentUser`:
- ❌ `profile`
- ❌ `updateProfile`
- ❌ `toJson` (the library now takes care of converting the response to JSON).
* Renames all of the remaining API methods:
- `search`:
- ⚠️ `photos` --> `getPhotos`
- ⚠️ `users` --> `getUsers`
- ⚠️ `collections` --> `getCollections`
- `photos`:
- ⚠️ `listPhotos` --> `list`
- ⚠️ `getPhoto` --> `get`
- ⚠️ `getRandomPhoto` --> `getRandom`
- ⚠️ `getPhotoStats` --> `getStats`
- `users`:
- ⚠️ `profile` --> `get`
- ⚠️ `photos` --> `getPhotos`
- ⚠️ `likes` --> `getLikes`
- ⚠️ `collections` --> `getCollections`
- `collections`:
- ⚠️ `listCollections` --> `list`
- ⚠️ `getCollection` --> `get`
- ⚠️ `getCollectionPhotos` --> `getPhotos`
- ⚠️ `listRelatedCollections` --> `listRelated`
- Changes the format of the parameters for **all** API methods. They are now all named parameters within the first argument, instead of multiple arguments. Check the TypeScript types and the [Arguments](./README.md#Arguments) section of the docs for the new parameters format.
- Changes the format of the responses for **all** API methods. The JSON is now parsed and returned, removing the need for the `toJson` helper. Feeds have the "x-total" header added to the response. The library now also performs error-handling: expected errors are returned instead of thrown, along with a description of their source. Check the TypeScript types and the [Response](./README.md#Response) section of the docs for the new response format.
### Changes
- TypeScript support! Everything is now accurately typed (except responses which we plan to add types for soon).
- You can now provide fetch options on a per-call basis using the second parameter. See [Arguments](./README.md#Arguments).
## 6.3.0

@@ -7,3 +83,3 @@

- Deprecate `photos.photoDownload` in favor of `photos.trackDownload` to better clarify method usage. `photoDownload` will continue to be supported until version 7.0.
- Deprecate `photos.downloadPhoto` in favor of `photos.trackDownload` to better clarify method usage. `downloadPhoto` will continue to be supported until version 7.0.

@@ -17,3 +93,3 @@ ## 6.2.0

```js
unsplash.search.photos("nature", 1, 10, { lang: "en" });
unsplash.search.photos('nature', 1, 10, { lang: 'en' });
```

@@ -24,6 +100,6 @@

```js
unsplash.search.photos("nature", 1, 10, {
orientation: "landscape",
color: "green", // new
orderBy: "relevant" // new
unsplash.search.photos('nature', 1, 10, {
orientation: 'landscape',
color: 'green', // new
orderBy: 'relevant', // new
});

@@ -35,3 +111,3 @@ ```

```js
unsplash.search.photos("nature", 1, 10, { contentFilter: "high" });
unsplash.search.photos('nature', 1, 10, { contentFilter: 'high' });
```

@@ -50,6 +126,7 @@

- To better clarify the use of `accessKey` when initializing, `applicationId` has been renamed to `accessKey`:
```js
// previously
const unsplash = new Unsplash({
applicationId: "{APP_ACCESS_KEY}"
applicationId: '{APP_ACCESS_KEY}',
});

@@ -59,5 +136,6 @@

const unsplash = new Unsplash({
accessKey: "{APP_ACCESS_KEY}"
accessKey: '{APP_ACCESS_KEY}',
});
```
- `unsplash.photos.getPhotoStats` now uses the `/photos/:id/statistics` endpoint ([changelog reference](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html))

@@ -68,3 +146,3 @@

```js
unsplash.search.photos("nature", 1, 10, { orientation: "landscape", collections: [1,2] })
unsplash.search.photos('nature', 1, 10, { orientation: 'landscape', collections: [1, 2] });
```

@@ -76,19 +154,19 @@

| Removed Method | Replacement | Reason |
|---|---|---|
| `unsplash.search.all` | None | This endpoint is undocumented publicly and is highly likely to change in the future. Therefore, we don't recommend anyone use this functionality in their applications. |
| `unsplash.photos.listCuratedPhotos` | None | Curated photos were [deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.photos.searchPhotos` | `unsplash.search.photos` | Replaced by [the new search endpoints in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) |
| `unsplash.photos.uploadPhoto` | None | Removed for legal compatibility |
| `unsplash.collections.listFeaturedCollections` | `unsplash.collections.listCollections` | Redundant endpoint |
| `unsplash.collections.listCuratedCollections` | None | Curated collections were replaced by collections. [Deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.collections.getCuratedCollection` | `unsplash.collections.getCollection` | Curated collections were replaced by collections. [Deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| Removed Method | Replacement | Reason |
| ------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `unsplash.search.all` | None | This endpoint is undocumented publicly and is highly likely to change in the future. Therefore, we don't recommend anyone use this functionality in their applications. |
| `unsplash.photos.listCuratedPhotos` | None | Curated photos were [deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.photos.searchPhotos` | `unsplash.search.photos` | Replaced by [the new search endpoints in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) |
| `unsplash.photos.uploadPhoto` | None | Removed for legal compatibility |
| `unsplash.collections.listFeaturedCollections` | `unsplash.collections.listCollections` | Redundant endpoint |
| `unsplash.collections.listCuratedCollections` | None | Curated collections were replaced by collections. [Deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.collections.getCuratedCollection` | `unsplash.collections.getCollection` | Curated collections were replaced by collections. [Deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.collections.getCuratedCollectionPhotos` | `unsplash.collections.getCollectionPhotos` | Curated collections were replaced by collections. [Deprecated in 2017](https://changelog.unsplash.com/deprecations/2018/09/27/curated-collections-deprecation.html), [removed in 2019](https://changelog.unsplash.com/deprecations/2019/09/23/curated-collections-removal.html) |
| `unsplash.categories.*` | None | [Categories were deprecated in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) and [removed from the API in 2017](https://changelog.unsplash.com/deprecations/2018/04/20/categories-eol.html) |
| `unsplash.categories.*` | None | [Categories were deprecated in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) and [removed from the API in 2017](https://changelog.unsplash.com/deprecations/2018/04/20/categories-eol.html) |
| Removed Parameter | Method | Reason |
|---|---|---|
| `category` | `unsplash.photos.getRandomPhoto` | [Categories were deprecated in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) and [removed from the API in 2017](https://changelog.unsplash.com/deprecations/2018/04/20/categories-eol.html) |
| `w` | `unsplash.photos.getPhoto`, `unsplash.photos.getRandomPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |
| `h` | `unsplash.photos.getPhoto`, `unsplash.photos.getRandomPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |
| `crop` | `unsplash.photos.getPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |
| Removed Parameter | Method | Reason |
| ----------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `category` | `unsplash.photos.getRandomPhoto` | [Categories were deprecated in 2017](https://changelog.unsplash.com/deprecations/2017/10/05/existing-deprecations.html) and [removed from the API in 2017](https://changelog.unsplash.com/deprecations/2018/04/20/categories-eol.html) |
| `w` | `unsplash.photos.getPhoto`, `unsplash.photos.getRandomPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |
| `h` | `unsplash.photos.getPhoto`, `unsplash.photos.getRandomPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |
| `crop` | `unsplash.photos.getPhoto` | [Deprecated in favor of dynamic image URLs](https://changelog.unsplash.com/2019/03/19/image-resizing.html) |

92

package.json
{
"name": "unsplash-js",
"version": "6.3.0",
"version": "7.0.0-beta.1",
"description": "A JavaScript wrapper for the Unsplash API",
"main": "lib/unsplash.js",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"scripts": {
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min && npm run build:examples",
"build:examples": "cp dist/unsplash.min.js examples/umd/public/unsplash.min.js",
"build:lib": "babel src --out-dir lib",
"build:umd": "webpack src/unsplash.js dist/unsplash.js --config webpack.config.development.js",
"build:umd:min": "webpack src/unsplash.js dist/unsplash.min.js --config webpack.config.production.js",
"build:watch": "babel src --watch --out-dir lib",
"lint": "eslint src",
"test": "npm run lint && npm run test:node",
"test:node": "mocha --compilers js:babel-core/register --require test/setup --recursive",
"test:watch": "npm test -- --watch",
"prepublish": "npm run build",
"publish:major": "npm run build && npm version major",
"publish:minor": "npm run build && npm version minor",
"publish:patch": "npm run build && npm version patch"
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why"
},
"resolutions": {
"typescript": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.8.2"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 100,
"semi": true,
"singleQuote": true,
"trailingComma": "all"
},
"module": "dist/unsplash-js.esm.js",
"size-limit": [
{
"path": "dist/unsplash-js.cjs.production.min.js",
"limit": "5 KB"
},
{
"path": "dist/unsplash-js.esm.js",
"limit": "5 KB"
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^4.9.0",
"husky": "^4.3.0",
"rollup-plugin-analyzer": "^3.3.0",
"size-limit": "^4.9.0",
"tsdx": "^0.14.1",
"tslib": "^2.0.3"
},
"repository": {

@@ -40,25 +77,6 @@ "type": "git",

"homepage": "https://github.com/unsplash/unsplash-js#readme",
"devDependencies": {
"babel": "6.3.26",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-eslint": "5.0.0-beta10",
"babel-loader": "6.2.1",
"babel-plugin-transform-class-properties": "6.4.0",
"babel-plugin-transform-object-assign": "6.3.13",
"babel-preset-es2015": "6.3.13",
"eslint": "1.10.2",
"expect": "1.12.2",
"istanbul": "0.4.2",
"mocha": "2.3.3",
"mockery": "1.4.0",
"node-fetch": "2.6.0",
"webpack": "1.12.14"
},
"dependencies": {
"form-urlencoded": "1.2.0",
"lodash.get": "4.4.2",
"querystring": "0.2.0",
"url-parse": "1.4.5"
"@types/content-type": "^1.1.3",
"content-type": "^1.0.4"
}
}
# Unsplash
[![npm](https://img.shields.io/npm/v/unsplash-js.svg?style=flat-square)](https://www.npmjs.com/package/unsplash-js)
[![Travis](https://img.shields.io/travis/unsplash/unsplash-js/master.svg?style=flat-square)](https://travis-ci.org/unsplash/unsplash-js/branches)
A server-side Javascript wrapper for working with the [Unsplash API](https://unsplash.com/developers).
Official Javascript wrapper for the [Unsplash API](https://unsplash.com/developers).
Before using the Unsplash API, you need to [register as a developer](https://unsplash.com/developers) and read the [API Guidelines](https://help.unsplash.com/api-guidelines/unsplash-api-guidelines).
## Quick start
Quick links to methods you're likely to care about:
- [Get a list of new photos](#photos-all) πŸŽ‰
- [Get a random photo](#photo-random) πŸŽ‘
- [Trigger a photo download](#track-download) πŸ“‘
- [Search for a photo by keyword](#search-photos) πŸ•΅οΈβ€β™‚οΈ
**Note:** Every application must abide by the [API Guidelines](https://help.unsplash.com/api-guidelines/unsplash-api-guidelines). Specifically, remember to [hotlink images](https://help.unsplash.com/api-guidelines/more-on-each-guideline/guideline-hotlinking-images), [attribute photographers](https://help.unsplash.com/api-guidelines/more-on-each-guideline/guideline-attribution), and [trigger a download when appropriate](https://help.unsplash.com/api-guidelines/more-on-each-guideline/guideline-triggering-a-download).
## Documentation
- [Installation](https://github.com/unsplash/unsplash-js#installation)
- [Dependencies](https://github.com/unsplash/unsplash-js#dependencies)
- [Usage](https://github.com/unsplash/unsplash-js#usage)
- [Instance Methods](https://github.com/unsplash/unsplash-js#instance-methods)
- [Helpers](https://github.com/unsplash/unsplash-js#helpers)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Usage](#usage)
- [Types](#types)
- [Instance Methods](#instance-methods)
## Installation
```bash
$ npm i --save unsplash-js
```
## Dependencies
This library depends on [fetch](https://fetch.spec.whatwg.org/) to make requests to the Unsplash API. For environments that don't support fetch, you'll need to provide a [polyfill](https://github.com/bitinn/node-fetch).
# OR
```js
// ES Modules syntax
import fetch from 'node-fetch';
global.fetch = fetch;
// require syntax
const fetch = require('node-fetch');
global.fetch = fetch;
$ yarn add unsplash-js
```
Note: we recommend using a version of `node-fetch` higher than `2.4.0` to benefit from Brotli compression.
## Dependencies
## Usage
### Fetch
If you're using `unsplash-js` publicly in the browser, you'll need to proxy your requests through your server to sign the requests with the Access Key and/or Secret Key to abide by the [API Guideline](https://help.unsplash.com/articles/2511245-unsplash-api-guidelines) to keep keys confidential.
This library depends on [fetch](https://fetch.spec.whatwg.org/) to make requests to the Unsplash API. For environments that don't support fetch, you'll need to provide polyfills of your choosing. Here are the ones we recommend:
### Creating an instance
To create an instance, simply provide an _Object_ with your `accessKey`:
- node implementation: [node-fetch](https://github.com/bitinn/node-fetch)
- browser polyfill: [whatwg-fetch](https://github.com/github/fetch)
```js
// ES Modules syntax
import Unsplash, { toJson } from 'unsplash-js';
// require syntax
const Unsplash = require('unsplash-js').default;
const toJson = require('unsplash-js').toJson;
```ts
// server
import fetch from 'node-fetch';
global.fetch = fetch;
const unsplash = new Unsplash({ accessKey: APP_ACCESS_KEY });
const unsplash = new Unsplash({
accessKey: APP_ACCESS_KEY,
// Optionally you can also configure a custom header to be sent with every request
headers: {
"X-Custom-Header": "foo"
},
// Optionally if using a node-fetch polyfill or a version of fetch which supports the timeout option, you can configure the request timeout for all requests
timeout: 500 // values set in ms
});
// browser
import 'whatwg-fetch';
```
_Credentials can be obtained from [Unsplash Developers](https://unsplash.com/developers)._
Note: we recommend using a version of `node-fetch` higher than `2.4.0` to benefit from Brotli compression.
---
### URL
### Error handling
```js
unsplash.users.profile("naoufal")
.catch(err => {
// Your flawless error handling code
});
```
This library also depends on the WHATWG URL interface:
---
- MDN [docs](https://developer.mozilla.org/en-US/docs/Web/API/URL) for browsers.
- NodeJS [docs](https://nodejs.org/api/url.html).
## Instance Methods
Make sure to polyfill this interface if targetting older environments that do not implement it (i.e. Internet Explorer or a Node version older than [v8](https://nodejs.org/es/blog/release/v8.0.0/#say-hello-to-the-whatwg-url-parser))
- [Search](https://github.com/unsplash/unsplash-js#search)
- [Photos](https://github.com/unsplash/unsplash-js#photos)
- [Users](https://github.com/unsplash/unsplash-js#users)
- [Collections](https://github.com/unsplash/unsplash-js#collections)
- [User Authorization](https://github.com/unsplash/unsplash-js#user-authorization)
- [Current User](https://github.com/unsplash/unsplash-js#current-user)
## Usage
All the instance methods below make use of the `toJson` helper method described [below](https://github.com/unsplash/unsplash-js#tojsonres)
### Creating an instance
---
To create an instance, simply provide an _Object_ with your `accessKey`.
<div id="search" />
NOTE: If you're using `unsplash-js` publicly in the browser, you'll need to proxy your requests through your server to sign the requests with the Access Key to abide by the [API Guideline](https://help.unsplash.com/articles/2511245-unsplash-api-guidelines) to keep keys confidential. We provide an `apiUrl` property that lets you do so. You should only need to provide _one_ of those two values in any given scenario.
<div id="search-photos" />
```ts
import { createApi } from 'unsplash-js';
### search.photos(keyword, page, per_page, options)
Get a list of photos matching the keyword. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-photos)
// on your node server
const serverApi = createApi({
accessKey: 'MY_ACCESS_KEY',
//...other fetch options
});
__Arguments__
| Argument | Type | Optional/Required | Default |
|---|---|---|---|
|__`keyword`__|_string_|Required||
|__`page`__|_number_|Optional|1|
|__`per_page`__|_number_|Optional|10|
|__`options`__|_object_|Optional||
|__`options.orientation`__|_string_|Optional||
|__`options.contentFilter`__|_string_|Optional|"low"|
|__`options.color`__|_string_|Optional||
|__`options.orderBy`__|_string_|Optional|"relevant"|
|__`options.collections`__|_array_|Optional||
|__`options.lang`__|_string_|Optional|"en"|
See the [API documentation for the possible option values](https://unsplash.com/documentation#parameters-16).
__Example__
```js
unsplash.search.photos("dogs", 1, 10, { orientation: "portrait", color: "green" })
.then(toJson)
.then(json => {
// Your code
});
// in the browser
const browserApi = createApi({
apiUrl: 'https://mywebsite.com/unsplash-proxy',
//...other fetch options
});
```
### search.users(keyword, page, per_page)
Get a list of users matching the keyword. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-users)
### Making a request
__Arguments__
#### Arguments
| Argument | Type | Opt/Required | Default |
|---|---|---|---|
|__`keyword`__|_string_|Required||
|__`page`__|_number_|Optional|1|
|__`per_page`__|_number_|Optional|10|
All methods have 2 arguments: the first one includes all of the specific parameters for that particular endpoint, while the second allows you to pass down any additional options that you want to provide to `fetch`. On top of that, the `createApi` constructor can receive `fetch` options to be added to _every_ request:
```ts
const unsplash = createApi({
accessKey: 'MY_ACCESS_KEY',
// `fetch` options to be sent with every request
headers: { 'X-Custom-Header': 'foo' },
});
__Example__
```js
unsplash.search.users("steve", 1)
.then(toJson)
.then(json => {
// Your code
});
unsplash.photos.get(
{ photoId: '123' },
// `fetch` options to be sent only with _this_ request
{ headers: { 'X-Custom-Header-2': 'bar' } },
);
```
### search.collections(keyword, page, per_page)
Get a list of collections matching the keyword. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-collections)
Example: if you would like to implement [request abortion](https://developer.mozilla.org/en-US/docs/Web/API/AbortController), you can do so like this:
__Arguments__
```ts
const unsplash = createApi({
accessKey: 'MY_ACCESS_KEY',
});
| Argument | Type | Opt/Required | Default |
|---|---|---|---|
|__`keyword`__|_string_|Required||
|__`page`__|_number_|Optional|1|
|__`per_page`__|_number_|Optional|10|
const controller = new AbortController();
const signal = controller.signal;
unsplash.photos.get({ photoId: '123' }, { signal }).catch(err => {
if (err.name === 'AbortError') {
console.log('Fetch aborted');
}
});
__Example__
```js
unsplash.search.collections("dogs", 1)
.then(toJson)
.then(json => {
// Your code
});
controller.abort();
```
---
#### Response
<div id="photos" />
When making a request using this SDK, there are 2 possible outcomes to a request.
<div id="photos-all" />
- Error: we return a `result.errors` object containing an array of strings (each one representing one error) and `result.source` describing the origin of the error (e.g. `api`, `decoding`). Typically, you will only have on item in this array.
- Success: we return a `result.response` object containing the data.
- If the request is for a page from a feed, then `result.response.results` will contain the JSON received from API, and `result.response.total` will contain the [`X-total` header value](https://unsplash.com/documentation#per-page-and-total) indicating the total number of items in the feed (not just the page you asked for).
- If the request is something other than a feed, then `result.response` will contain the JSON received from API
### photos.listPhotos(page, perPage, orderBy)
Get a single page from the list of all photos. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-photos)
You can inspect which one you have by reading the `result.type` value or checking the contents of `result.errors`/`result.success`
__Arguments__
```ts
const unsplash = createApi({ accessKey: 'MY_ACCESS_KEY' });
| Argument | Type | Opt/Required | Default |
|---|---|---|
|__`page`__|_number_|Optional|1|
|__`perPage`__|_number_|Optional|10|
|__`orderBy`__|_string_|Optional|`latest`|
// non-feed example
unsplash.photos.get({ photoId: 'foo' }).then(result => {
if (result.errors) {
// handle error here
console.log('error occurred: ', result.errors[0]);
} else {
// handle success here
const photo = result.response;
console.log(photo);
}
});
__Example__
```js
unsplash.photos.listPhotos(2, 15, "latest")
.then(toJson)
.then(json => {
// Your code
});
```
---
// feed example
unsplash.users.getPhotos({ username: 'foo' }).then(result => {
if (result.errors) {
// handle error here
console.log('error occurred: ', result.errors[0]);
} else {
const feed = result.response;
### photos.getPhoto(id)
Retrieve a single photo. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-photo)
// extract total and results array from response
const { total, results } = feed;
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_string_|Required|
__Example__
```js
unsplash.photos.getPhoto("mtNweauBsMQ")
.then(toJson)
.then(json => {
// Your code
});
// handle success here
console.log(`received ${results.length} photos out of ${total}`);
console.log('first photo: ', results[0]);
}
});
```
---
### photos.getPhotoStats(id)
Retrieve a single photo's stats. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-photos-statistics)
NOTE: you can also pattern-match on `result.type` whose value will be `error` or `success`:
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_string_|Required|
__Example__
```js
unsplash.photos.getPhotoStats("mtNweauBsMQ")
.then(toJson)
.then(json => {
// Your code
});
```ts
unsplash.photos.get({ photoId: 'foo' }).then(result => {
switch (result.type) {
case 'error':
console.log('error occurred: ', result.errors[0]);
case 'success':
const photo = result.response;
console.log(photo);
}
});
```
---
<div id="photo-random" />
## Types
### photos.getRandomPhoto({ query, username, featured })
Retrieve a single random photo, given optional filters. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-random-photo)
This library is written in TypeScript. This means that even if you are writing plain JavaScript, you can still get useful and accurate type information. We highly recommend that you setup your environment (using an IDE such as [VSCode](https://code.visualstudio.com/)) to fully benefit from this information:
When using this function, It is recommended to double check the types of the parameters,
in particular for the parameters of type Array<number>.
![](./vscode-screenshot2.png)
![](./vscode-screenshot.png)
__Arguments__
## Instance Methods
Argument 1:
_An Object containing the follow keys:_
NOTE: All of the method arguments described here are in the first parameter. See the [arguments](#Arguments) section for more information.
| Argument | Type | Opt/Required |
|---|---|---|
|__`query`__|_string_|Optional|
|__`username`__|_string_|Optional|
|__`featured`__|_boolean_|Optional|
|__`collections`__|_Array<number>_|Optional|
|__`count`__|_string_|Optional|
- [Search](https://github.com/unsplash/unsplash-js#search)
- [Photos](https://github.com/unsplash/unsplash-js#photos)
- [Users](https://github.com/unsplash/unsplash-js#users)
- [Collections](https://github.com/unsplash/unsplash-js#collections)
__Example__
```js
unsplash.photos.getRandomPhoto({ username: "naoufal" })
.then(toJson)
.then(json => {
// Your code
});
```
---
### photos.likePhoto(id)
Like a photo on behalf of the logged-in user. This requires the `write_likes` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#like-a-photo)
<div id="search" />
__Arguments__
<div id="search-photos" />
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_string_|Required|
### search.getPhotos(arguments, additionalFetchOptions)
__Example__
```js
unsplash.photos.likePhoto("mtNweauBsMQ")
.then(toJson)
.then(json => {
// Your code
});
```
---
Get a list of photos matching the query. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-photos)
### photos.unlikePhoto(id)
Remove a user’s like of a photo. [See endpoint docs πŸš€](https://unsplash.com/documentation#unlike-a-photo)
**Arguments**
__Arguments__
| Argument | Type | Optional/Required | Default |
| ------------------- | -------- | ----------------- | ---------- |
| **`query`** | _string_ | Required | |
| **`page`** | _number_ | Optional | 1 |
| **`perPage`** | _number_ | Optional | 10 |
| **`orientation`** | _string_ | Optional | |
| **`contentFilter`** | _string_ | Optional | "low" |
| **`color`** | _string_ | Optional | |
| **`orderBy`** | _string_ | Optional | "relevant" |
| **`collectionIds`** | _array_ | Optional | |
| **`lang`** | _string_ | Optional | "en" |
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_string_|Required|
**Example**
__Example__
```js
unsplash.photos.unlikePhoto("mtNweauBsMQ")
.then(toJson)
.then(json => {
// Your code
});
unsplash.search.getPhotos({
query: 'cat',
page: 1,
perPage: 10,
color: 'green',
orientation: 'portrait',
});
```
---
<div id="track-download" />
### search.getUsers(arguments, additionalFetchOptions)
### photos.trackDownload(photo)
Trigger a download of a photo as per the [download tracking requirement of API Guidelines](https://medium.com/unsplash/unsplash-api-guidelines-triggering-a-download-c39b24e99e02). [See endpoint docs πŸš€](https://unsplash.com/documentation#track-a-photo-download)
Get a list of users matching the query. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-users)
*Note*: this accepts a photo JSON object, not a URL string or photo ID. See the example below for how to pair it with other calls to trigger it.
**Arguments**
__Arguments__
| Argument | Type | Opt/Required | Default |
| ------------- | -------- | ------------ | ------- |
| **`query`** | _string_ | Required | |
| **`page`** | _number_ | Optional | 1 |
| **`perPage`** | _number_ | Optional | 10 |
| Argument | Type | Opt/Required |
|---|---|---|
|__`photo`__|_json_|Required|
**Example**
__Example__
```js
unsplash.photos.getPhoto("mtNweauBsMQ")
.then(toJson)
.then(json => {
unsplash.photos.trackDownload(json);
});
// or if working with an array of photos
unsplash.search.photos("dogs", 1)
.then(toJson)
.then(json => {
unsplash.photos.trackDownload(json["results"][0]);
});
unsplash.search.getUsers({
query: 'cat',
page: 1,
perPage: 10,
});
```
---
### search.getCollections(arguments, additionalFetchOptions)
<div id="users" />
Get a list of collections matching the query. [See endpoint docs πŸš€](https://unsplash.com/documentation#search-collections)
### users.profile(username)
Retrieve public details on a given user. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-users-public-profile)
**Arguments**
__Arguments__
| Argument | Type | Opt/Required | Default |
| ------------- | -------- | ------------ | ------- |
| **`query`** | _string_ | Required | |
| **`page`** | _number_ | Optional | 1 |
| **`perPage`** | _number_ | Optional | 10 |
| Argument | Type | Opt/Required |
|---|---|---|
|__`username`__|_string_|Required|
**Example**
__Example__
```js
unsplash.users.profile("naoufal")
.then(toJson)
.then(json => {
// Your code
});
unsplash.search.getCollections({
query: 'cat',
page: 1,
perPage: 10,
});
```
---
### users.statistics(username, resolution, quantity)
Retrieve statistics for a given user. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-users-statistics)
<div id="photos" />
__Arguments__
<div id="photos-all" />
| Argument | Type | Opt/Required | Notes | Default
|---|---|---|---|---|
|__`username`__|_string_|Required|
|__`resolution`__|_string_|Optional|Currently only `days`|`days`|
|__`quantity`__|_string_|Optional||30|
### photos.list(arguments, additionalFetchOptions)
Get a single page from the list of all photos. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-photos)
__Example__
```js
unsplash.users.statistics("naoufal", "days", 30)
.then(toJson)
.then(json => {
// Your code
});
```
---
**Arguments**
### users.photos(username, page, perPage, orderBy, options)
Get a list of photos uploaded by a user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-photos)
| Argument | Type | Opt/Required | Default |
| ------------- | -------- | ------------ | -------- |
| **`page`** | _number_ | Optional | 1 |
| **`perPage`** | _number_ | Optional | 10 |
| **`orderBy`** | _string_ | Optional | `latest` |
__Arguments__
**Example**
| Argument | Type | Opt/Required | Notes | Default |
|---|---|---|---|---|
|__`username`__|_string_|Required|||
|__`page`__|_number_|Optional||1|
|__`perPage`__|_number_|Optional||10|
|__`orderBy`__|_string_|Optional|`latest`, `oldest`|`latest`|
|__`options`__|_object_|Optional|
|__`options.stats`__|_boolean_|Optional||`false`|
|__`options.orientation`__|_string_|Optional|`landscape`, `portrait`, `squarish`|
__Example__
```js
unsplash.users.photos("naoufal", 1, 10, "latest", { orientation: "landscape" })
.then(toJson)
.then(json => {
// Your code
});
unsplash.photos.list();
unsplash.photos.list({ page: 2, page: 15 });
```
---
### users.likes(username, page, perPage, orderBy, options)
Get a list of photos liked by a user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-liked-photos)
### photos.get(arguments, additionalFetchOptions)
__Arguments__
Retrieve a single photo. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-photo)
| Argument | Type | Opt/Required | Notes | Default |
|---|---|---|---|
|__`username`__|_string_|Required||
|__`page`__|_number_|Optional||1|
|__`perPage`__|_number_|Optional||10|
|__`orderBy`__|_string_|Optional|`latest`, `oldest`|`latest`|
|__`options`__|_object_|Optional||
|__`options.orientation`__|_string_|Optional|`landscape`, `portrait`, `squarish`||
**Arguments**
__Example__
```js
unsplash.users.likes("naoufal", 2, 15, "latest", { orientation: "landscape" })
.then(toJson)
.then(json => {
// Your code
});
```
---
| Argument | Type | Opt/Required |
| ------------- | -------- | ------------ |
| **`photoId`** | _string_ | Required |
### users.collections(username, page, perPage, orderBy)
Get a list of collections created by the user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-collections)
**Example**
__Arguments__
| Argument | Type | Opt/Required | Notes | Default |
|---|---|---|---|
|__`username`__|_string_|Required|||
|__`page`__|_number_|Optional||1|
|__`perPage`__|_number_|Optional||10|
|__`orderBy`__|_string_|Optional|`published` or `updated`|`updated`|
__Example__
```js
unsplash.users.collections("naoufal", 2, 15, "updated")
.then(toJson)
.then(json => {
// Your code
});
unsplash.photos.get({ photoId: 'mtNweauBsMQ' });
```
---
<div id="collections" />
### photos.getStats(arguments, additionalFetchOptions)
### collections.listCollections(page, perPage, orderBy)
Get a single page from the list of all collections. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-collections)
Retrieve a single photo's stats. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-photos-statistics)
__Arguments__
**Arguments**
| Argument | Type | Opt/Required | Notes | Default |
|---|---|---|---|
|__`page`__|_number_|Optional||1|
|__`perPage`__|_number_|Optional||10|
|__`orderBy`__|_string_|Optional|`latest`, `oldest`|`latest`|
| Argument | Type | Opt/Required |
| ------------- | -------- | ------------ |
| **`photoId`** | _string_ | Required |
__Example__
**Example**
```js
unsplash.collections.listCollections(1, 10, "latest")
.then(toJson)
.then(json => {
// Your code
});
unsplash.photos.getStats({ photoId: 'mtNweauBsMQ' });
```
---
### collections.getCollection(id)
Retrieve a single collection. To view a user’s private collections, the `read_collections` scope is required. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-collection)
<div id="photo-random" />
__Arguments__
### photos.getRandom(arguments, additionalFetchOptions)
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
Retrieve a single random photo, given optional filters. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-random-photo). Note: if you provide a value for `count` greater than `1`, you will receive an array of photos. Otherwise, you will receive a single photo object.
**Arguments**
__Example__
```js
unsplash.collections.getCollection(123456)
.then(toJson)
.then(json => {
// Your code
});
```
---
| Argument | Type | Opt/Required |
| ------------------- | --------------- | ------------ |
| **`query`** | _string_ | Optional |
| **`username`** | _string_ | Optional |
| **`featured`** | _boolean_ | Optional |
| **`collectionIds`** | _Array<number>_ | Optional |
| **`count`** | _string_ | Optional |
### collections.getCollectionPhotos(id, page, perPage, orderBy, options)
Retrieve a collection’s photos. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-collections-photos)
**Example**
__Arguments__
| Argument | Type | Opt/Required | Notes | Default |
|---|---|---|---|
|__`id`__|_number_|Required|||
|__`page`__|_number_|Optional||1|
|__`perPage`__|_number_|Optional||10|
|__`orderBy`__|_string_|Optional|`latest`, `oldest`|`latest`|
|__`options`__|_object_|Optional|
|__`options.orientation`__|_string_|Optional| `landscape`, `portrait`, `squarish`|
__Example__
```js
unsplash.collections.getCollectionPhotos(123456, 1, 10, "latest")
.then(toJson)
.then(json => {
// Your code
});
unsplash.photos.getRandom();
unsplash.photos.getRandom({
count: 10,
});
unsplash.photos.getRandom({
collectionIds: ['abc123'],
featured: true,
username: 'naoufal',
query: 'dog',
count: 1,
});
```
---
### collections.createCollection(title, description, private)
Create a new collection. This requires the `write_collections` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#create-a-new-collection)
<div id="track-download" />
__Arguments__
### photos.trackDownload(arguments, additionalFetchOptions)
| Argument | Type | Opt/Required |
|---|---|---|
|__`title`__|_string_|Required|
|__`description`__|_string_|Optional|
|__`private`__|_boolean_|Optional|
Trigger a download of a photo as per the [download tracking requirement of API Guidelines](https://medium.com/unsplash/unsplash-api-guidelines-triggering-a-download-c39b24e99e02). [See endpoint docs πŸš€](https://unsplash.com/documentation#track-a-photo-download)
__Example__
```js
unsplash.collections.createCollection("Birds", "Wild birds from 'round the world", true)
.then(toJson)
.then(json => {
// Your code
});
```
---
**Arguments**
### collections.updateCollection(id, title, description, private)
Update an existing collection belonging to the logged-in user. This requires the `write_collections` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#update-an-existing-collection)
| Argument | Type | Opt/Required |
| ---------------------- | -------- | ------------ |
| **`downloadLocation`** | _string_ | Required |
__Arguments__
**Example**
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
|__`title`__|_string_|Optional|
|__`description`__|_string_|Optional|
|__`private`__|_boolean_|Optional|
```js
unsplash.photos.get({ photoId: 'mtNweauBsMQ' }).then(result => {
if (result.type === 'success') {
const photo = result.response;
unsplash.photos.trackDownload({
downloadLocation: photo.links.downloadLocation,
});
}
});
__Example__
```js
unsplash.collections.updateCollection(12345, "Wild Birds", "Wild birds from around the world", false)
.then(toJson)
.then(json => {
// Your code
});
// or if working with an array of photos
unsplash.search.photos({ query: 'dogs' }).then(result => {
if (result.type === 'success') {
const firstPhoto = result.response.results[0];
unsplash.photos.trackDownload({
downloadLocation: photo.links.downloadLocation,
});
}
});
```
---
### collections.deleteCollection(id)
Delete a collection belonging to the logged-in user. This requires the `write_collections` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#delete-a-collection)
<div id="users" />
__Arguments__
### users.get(username)
| Argument | Type | Opt/Required |
|---|---|---|
|__`id`__|_number_|Required|
Retrieve public details on a given user. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-users-public-profile)
**Arguments**
__Example__
```js
unsplash.collections.deleteCollection(88)
.then(toJson)
.then(json => {
// Your code
});
```
---
| Argument | Type | Opt/Required |
| -------------- | -------- | ------------ |
| **`username`** | _string_ | Required |
### collections.addPhotoToCollection(collectionId, photoId)
Add a photo to one of the logged-in user’s collections. Requires the `write_collections` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#add-a-photo-to-a-collection)
**Example**
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`collectionId`__|_number_|Required|
|__`photoId`__|_string_|Required|
__Example__
```js
unsplash.collections.addPhotoToCollection(88, 'abc1234')
.then(toJson)
.then(json => {
// Your code
});
unsplash.users.get({ username: 'naoufal' });
```
---
### collections.removePhotoFromCollection(collectionId, photoId)
Remove a photo from one of the logged-in user’s collections. Requires the `write_collections` scope. [See endpoint docs πŸš€](https://unsplash.com/documentation#remove-a-photo-from-a-collection)
### users.getPhotos(arguments, additionalFetchOptions)
__Arguments__
Get a list of photos uploaded by a user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-photos)
| Argument | Type | Opt/Required |
|---|---|---|
|__`collectionId`__|_number_|Required|
|__`photoId`__|_string_|Required|
**Arguments**
__Example__
```js
unsplash.collections.removePhotoFromCollection(88, 'abc1234')
.then(toJson)
.then(json => {
// Your code
});
```
---
| Argument | Type | Opt/Required | Notes | Default |
| ----------------- | --------- | ------------ | ----------------------------------- | -------- |
| **`username`** | _string_ | Required | | |
| **`page`** | _number_ | Optional | | 1 |
| **`perPage`** | _number_ | Optional | | 10 |
| **`orderBy`** | _string_ | Optional | `latest`, `oldest` | `latest` |
| **`stats`** | _boolean_ | Optional | | `false` |
| **`orientation`** | _string_ | Optional | `landscape`, `portrait`, `squarish` | |
### collections.listRelatedCollections(collectionId)
Lists collections related to the provided one. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-collections-related-collections)
**Example**
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`collectionId`__|_number_|Required|
__Example__
```js
unsplash.collections.listRelatedCollections(88)
.then(toJson)
.then(json => {
// Your code
});
unsplash.users.getPhotos({
username: 'naoufal',
page: 1,
perPage: 10,
orderBy: 'latest',
orientation: 'landscape',
});
```

@@ -648,186 +456,129 @@

<div id="user-authorization" />
### users.getLikes(arguments, additionalFetchOptions)
Note: Most endpoints do not need to be authenticated by an individual user to be accessed and can instead be accessed with [public authentication](https://unsplash.com/documentation#public-authentication). Endpoints that require user authentication will be explicitly marked with the required scopes.
Get a list of photos liked by a user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-liked-photos)
When initializing an instance of Unsplash, you'll need to include your application's `secretKey` and `callbackUrl` as defined in the [API documentation](https://unsplash.com/documentation/user-authentication-workflow):
**Arguments**
```js
const unsplash = new Unsplash({
accessKey: "{APP_ACCESS_KEY}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}"
});
```
| Argument | Type | Opt/Required | Notes | Default |
| ----------------- | -------- | ------------ | ----------------------------------- | -------- |
| **`username`** | _string_ | Required | | |
| **`page`** | _number_ | Optional | | 1 |
| **`perPage`** | _number_ | Optional | | 10 |
| **`orderBy`** | _string_ | Optional | `latest`, `oldest` | `latest` |
| **`orientation`** | _string_ | Optional | `landscape`, `portrait`, `squarish` | |
If you already have a bearer token, you can also provide it to the constructor:
**Example**
```js
const unsplash = new Unsplash({
accessKey: "{APP_ACCESS_KEY}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}",
bearerToken: "{USER_BEARER_TOKEN}"
unsplash.users.getLikes({
username: 'naoufal',
page: 1,
perPage: 10,
orderBy: 'latest',
orientation: 'landscape',
});
```
Generate an authentication url with the scopes your app requires.
---
```js
const authenticationUrl = unsplash.auth.getAuthenticationUrl([
"public",
"read_user",
"write_user",
"read_photos",
"write_photos"
]);
```
### users.getCollections(arguments, additionalFetchOptions)
Now that you have an authentication url, you'll want to redirect the user to it.
Get a list of collections created by the user. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-users-collections)
```js
location.assign(authenticationUrl);
```
**Arguments**
After the user authorizes your app she'll be redirected to your callback url with a `code` querystring present. Request an access token using that code.
| Argument | Type | Opt/Required | Notes | Default |
| -------------- | -------- | ------------ | ----- | ------- |
| **`username`** | _string_ | Required | | |
| **`page`** | _number_ | Optional | | 1 |
| **`perPage`** | _number_ | Optional | | 10 |
**Example**
```js
// The OAuth code will be passed to your callback url as a querystring
unsplash.auth.userAuthentication(query.code)
.then(toJson)
.then(json => {
unsplash.auth.setBearerToken(json.access_token);
});
unsplash.users.getCollections({
username: 'naoufal',
page: 2,
perPage: 15,
});
```
_For more information on the authroization workflow, consult the [Unsplash API Documentation](https://unsplash.com/documentation/user-authentication-workflow)._
---
### auth.getAuthenticationUrl(scopes)
Build an OAuth url with requested scopes.
<div id="collections" />
__Arguments__
### collections.list(arguments, additionalFetchOptions)
| Argument | Type | Opt/Required | Default |
|---|---|---|---|
|__`scopes`__|_Array<string>_|Optional| `["public"]` |
Get a single page from the list of all collections. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-collections)
__Example__
```js
const authenticationUrl = unsplash.auth.getAuthenticationUrl([
"public",
"read_user",
"write_user",
"read_photos",
"write_photos"
]);
```
---
**Arguments**
### auth.userAuthentication(code)
Retrieve a user's access token.
| Argument | Type | Opt/Required | Notes | Default |
| ------------- | -------- | ------------ | ----- | ------- |
| **`page`** | _number_ | Optional | | 1 |
| **`perPage`** | _number_ | Optional | | 10 |
__Arguments__
**Example**
| Argument | Type | Opt/Required |
|---|---|---|
|__`code`__|_string_|Required|
__Example__
```js
unsplash.auth.userAuthentication("{OAUTH_CODE}")
.then(toJson)
.then(json => {
// Your code
});
unsplash.collections.list({ page: 1, perPage: 10 });
```
---
### auth.setBearerToken(accessToken)
Set a bearer token on the instance.
### collections.get(arguments, additionalFetchOptions)
__Arguments__
Retrieve a single collection. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-collection)
| Argument | Type | Opt/Required |
|---|---|---|
|__`accessToken`__|_string_|Required|
**Arguments**
__Example__
| Argument | Type | Opt/Required |
| ------------------ | -------- | ------------ |
| **`collectionId`** | _string_ | Required |
**Example**
```js
unsplash.auth.setBearerToken("{BEARER_TOKEN}");
unsplash.collections.get({ collectionId: 'abc123' });
```
---
<div id="current-user" />
### collections.getPhotos(arguments, additionalFetchOptions)
### currentUser.profile()
Get the user’s profile.
Retrieve a collection’s photos. [See endpoint docs πŸš€](https://unsplash.com/documentation#get-a-collections-photos)
__Arguments__
**Arguments**
_N/A_
| Argument | Type | Opt/Required | Notes | Default |
| ------------------ | -------- | ------------ | ----------------------------------- | -------- |
| **`collectionId`** | _string_ | Required | | |
| **`page`** | _number_ | Optional | | 1 |
| **`perPage`** | _number_ | Optional | | 10 |
| **`orderBy`** | _string_ | Optional | `latest`, `oldest` | `latest` |
| **`orientation`** | _string_ | Optional | `landscape`, `portrait`, `squarish` | |
__Example__
**Example**
```js
unsplash.currentUser.profile()
.then(toJson)
.then(json => {
// Your code
});
unsplash.collections.getPhotos({ collectionId: 'abc123' });
```
---
### currentUser.updateProfile(options)
Update the current user’s profile.
### collections.getRelated(arguments, additionalFetchOptions)
__Arguments__
Lists collections related to the provided one. [See endpoint docs πŸš€](https://unsplash.com/documentation#list-a-collections-related-collections)
| Argument | Type | Opt/Required |Notes|
|---|---|---|---|
|__`options`__|_Object_|Required|Object with the following optional keys: `username`, `firstName`, `lastName`, `email`, `url`, `location`, `bio`, `instagramUsername`|
**Arguments**
__Example__
```js
unsplash.currentUser.updateProfile({
username: "drizzy",
firstName: "Aubrey",
lastName: "Graham",
email: "drizzy@octobersveryown.com",
url: "http://octobersveryown.com",
location: "Toronto, Ontario, Canada",
bio: "Views from the 6",
instagramUsername: "champagnepapi"
})
.then(toJson)
.then(json => {
// Your code
});
```
---
| Argument | Type | Opt/Required |
| ------------------ | -------- | ------------ |
| **`collectionId`** | _string_ | Required |
## Helpers
**Example**
### toJson(res)
__Arguments__
| Argument | Type | Opt/Required |
|---|---|---|
|__`res`__|_Object_|Required|
__Example__
```js
import Unsplash, { toJson } from "unsplash-js";
const unsplash = new Unsplash({
accessKey: YOUR_ACCESS_KEY,
secret: YOUR_SECRET_KEY
});
unsplash.stats.total()
.then(toJson)
.then(json => {
// Your code
});
unsplash.collections.getRelated({ collectionId: 'abc123' });
```

Sorry, the diff of this file is not supported yet

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