box-node-sdk

FileVersionsManager

List all file versions

Retrieve a list of the past versions for a file.

Versions are only tracked by Box users with premium accounts. To fetch the ID of the current version of a file, use the GET /file/:id API.

This operation is performed by calling function getFileVersions.

See the endpoint docs at API Reference.

await client.fileVersions.getFileVersions(file.id);

Arguments

Returns

This function returns a value of type FileVersions.

Returns an array of past versions for this file.

Get file version

Retrieve a specific version of a file.

Versions are only tracked for Box users with premium accounts.

This operation is performed by calling function getFileVersionById.

See the endpoint docs at API Reference.

await client.fileVersions.getFileVersionById(
  file.id,
  fileVersions.entries![0].id,
);

Arguments

Returns

This function returns a value of type FileVersionFull.

Returns a specific version of a file.

Not all available fields are returned by default. Use the fields query parameter to explicitly request any specific fields.

Remove file version

Move a file version to the trash.

Versions are only tracked for Box users with premium accounts.

This operation is performed by calling function deleteFileVersionById.

See the endpoint docs at API Reference.

await client.fileVersions.deleteFileVersionById(file.id, fileVersion.id);

Arguments

Returns

This function returns a value of type undefined.

Returns an empty response when the file has been successfully deleted.

Restore file version

Restores a specific version of a file after it was deleted. Don’t use this endpoint to restore Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.

This operation is performed by calling function updateFileVersionById.

See the endpoint docs at API Reference.

await client.fileVersions.updateFileVersionById(file.id, fileVersion.id, {
  requestBody: {
    trashedAt: createNull(),
  } satisfies UpdateFileVersionByIdRequestBody,
} satisfies UpdateFileVersionByIdOptionalsInput);

Arguments

Returns

This function returns a value of type FileVersionFull.

Returns a restored file version object.

Promote file version

Promote a specific version of a file.

If previous versions exist, this method can be used to promote one of the older versions to the top of the version history.

This creates a new copy of the old version and puts it at the top of the versions history. The file will have the exact same contents as the older version, with the same hash digest, etag, and name as the original.

Other properties such as comments do not get updated to their former values.

Don’t use this endpoint to restore Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.

This operation is performed by calling function promoteFileVersion.

See the endpoint docs at API Reference.

await client.fileVersions.promoteFileVersion(file.id, {
  requestBody: {
    id: fileVersions.entries![0].id,
    type: 'file_version' as PromoteFileVersionRequestBodyTypeField,
  } satisfies PromoteFileVersionRequestBody,
} satisfies PromoteFileVersionOptionalsInput);

Arguments

Returns

This function returns a value of type FileVersionFull.

Returns a newly created file version object.