Skip to content

Class: PhotosResource

Photos Core

.delete(photoId): Promise<BaseOkay> Since1.0.0

DELETE /photos/{photo_id} API Docs
Deletes a photo

Parameters

NameTypeDescription
photoIdnumberPhoto identifier

Returns

Promise<BaseOkay>

Delete response

Throws

If photo ID is invalid

Example

javascript
await rest.photos.delete(123);

.get(photoId): Promise<Photo> Since1.0.0

GET /photos/{photo_id} API Docs
Gets a photo by identifier

Parameters

NameTypeDescription
photoIdstringPhoto identifier

Returns

Promise<Photo>

Photo object

Throws

If photo ID is invalid

Example

javascript
const photo = await rest.photos.get('123');

.getAll(page?, mode?): Promise<Photo[]> Since1.0.0

GET /photos No API Docs
Gets all photos (up to 12 per page)

Parameters

NameTypeDescription
page?numberPage number (optional)
mode?"private"Set to 'private' for private photos (optional)

Returns

Promise<Photo[]>

Array of Photo objects

Throws

If page number is invalid

Example

javascript
const photos = await rest.photos.getAll(2);
const privatePhotos = await rest.photos.getAll(0, 'private');

.upload(input, caption, mode, filename?): Promise<Photo> Since1.0.0

POST /photos/upload API Docs
Uploads a photo

Parameters

NameTypeDescription
inputstring | Blob | Buffer<ArrayBufferLike>Path to photo file or Buffer
caption?stringPhoto caption
mode?"public" | "private"Photo visibility mode
filename?stringCustom filename (optional)

Returns

Promise<Photo>

Photo Uploaded photo

Throws

If input is invalid or caption is too long

Example

javascript
const photo = await rest.photos.upload('/path/to/photo.jpg', 'My photo', 'public');
// or with Buffer
const photo = await rest.photos.upload(buffer, 'My photo', 'public', 'image.png');