Bulk delete documents using a script
Important: The use of this script deletes all documents not connected to a process, including documents that are referenced in draft processes and process models, as the linking of documents to processes happens at publish. If the documents are deleted they cannot be recovered.
Promasters A Nintex Process Manager system administrator who administers a Nintex Promapp site and has rights to view and edit all areas of a Nintex Promapp site. can bulk delete documents in Process Manager. To use the bulk delete functionality, you must first use a script in Microsoft Excel to export a list of documents in your Process Manager tenant. You then use a tool like Postman to delete selected documents using the bulk delete API endpoint.
Export a list of documents in Process Manager
Note: You can use the bulk delete option only for documents that are not archived and those that are not attached to processes.
To get a list of your documents in Process Manager:
-
Go to https://{{Tenant URL}}/exports/api/v1/reports/Documents/csv?includedGroups=true
This downloads a CSV file that contains details of all the documents in your Process Manager tenant, including their unique IDs.
-
In Microsoft Excel, open the file and click Format as Table to format the data.
-
Under Automate, click New Script.
-
Run the following script.
Automation script
Copyfunction main(workbook: ExcelScript.Workbook): DocumentItem[] {
let includeDocumentNamesInResult = false;
const pageSize = 500;
const currentWorksheet = workbook.getActiveWorksheet();
const table = currentWorksheet.getTables()[0];
const visibleView = table.getRange().getVisibleView();
const usedRange = currentWorksheet.getUsedRange();
const rows = visibleView.getValues() as string[][];
let returnObjects: DocumentItem[] = [];
returnObjects = returnObjectFromValues(rows, includeDocumentNamesInResult);
const documentBulkDeleteRequestInfo: DocumentBulkDeleteRequestInfo = {
DocumentItems: returnObjects
}
console.log("Total Item count:" + documentBulkDeleteRequestInfo.DocumentItems.length);
printResult(documentBulkDeleteRequestInfo, pageSize);
return returnObjects
}
function printResult(documentBulkDeleteRequestInfo: DocumentBulkDeleteRequestInfo, pageSize: number) {
let page = 1;
const totalPages = Math.ceil(documentBulkDeleteRequestInfo.DocumentItems.length / pageSize);
let temparray: DocumentItem[] = [];
let temp: DocumentBulkDeleteRequestInfo = {
DocumentItems: []
}
for (let i = 0; i < documentBulkDeleteRequestInfo.DocumentItems.length; i++) {
addToTempArray(temparray, documentBulkDeleteRequestInfo.DocumentItems[i]);
if (i == 0) {
continue;
}
if (temparray.length % pageSize == 0) {
prinPage(temparray, page, totalPages);
temparray = [];
page++;
}
}
if (temparray.length > 0) {
prinPage(temparray, page, totalPages);
}
}
function addToTempArray(temparray: DocumentItem[], item: DocumentItem) {
if (item != null) {
temparray.push(item);
}
}
function prinPage(temparray: DocumentItem[], page: number, totalPages: number) {
const temp = {
DocumentItems: temparray
}
console.log(JSON.stringify(temp));
console.log("--------------------Page " + page + " -of- " + totalPages + "--Count:" + temp.DocumentItems.length + "---------------------------")
}
function returnObjectFromValues(values: string[][], includeDocumentNamesInResult: boolean): DocumentItem[] {
let objectArray: DocumentItem[] = [];
let objectKeys: string[] = [];
for (let i = 0; i < values.length; i++) {
if (i === 0) {
objectKeys = values[i]
continue;
}
let object: { [key: string]: string } = {}
for (let j = 0; j < values[i].length; j++) {
if (objectKeys[j] != null || objectKeys[j] != undefined) {
var col = converHeaderName(objectKeys[j], includeDocumentNamesInResult);
if (col != null) {
object[col] = values[i][j]
}
}
}
objectArray.push(object as unknown as DocumentItem);
}
return objectArray;
}
function converHeaderName(value: string, includeDocumentNamesInResult: boolean): string {
switch (value) {
case "Document Name": {
if (includeDocumentNamesInResult === true) {
return "DocumentName";
}
}
case "Document Unique Id": return "DocumentUniqueId";
default: return null;
}
}
interface DocumentItem {
"DocumentName": string
"DocumentUniqueId": string
}
interface DocumentBulkDeleteRequestInfo {
"DocumentItems": DocumentItem[]
}The output provides all the document IDs in your tenant in a format that can be used by the bulk delete API.
Note: The output lists 500 documents per page.
Bulk deleting documents using Postman
To use the Bulk Delete API, you can use any API management tool like Postman. For more information on downloading and using Postman, see the Postman help documentation.

-
Open a new HTTP request in Postman.
-
Create a POST request in the following format:
POST: https://{{Tenant URL}}/oauth2/token
-
Under Body, select x-www-form-urlencoded and enter the following information:
Key Value grant_type password username {Promaster username} password {Promaster password} - Click Send.
The Bearer token is returned in the access_token property.
Create a bulk delete request
-
Open a new HTTP request.
-
Create a DELETE request in the following format:
DELETE: https://{{Tenant URL}}/documents/edit/BulkDeleteDocumentsAsync
-
Under Authorization, select Bearer Token and enter the access_token.
-
Under Body, for each document you want to delete, paste in the output from the script you ran in Excel.
For example: {"DocumentItems":[{"DocumentUniqueId":"1bbbdfa9-f79b-4cbd-9dc0-bd2a0871ad6f"}, {"DocumentUniqueId":"8a52b855-fc90-49a1-8da0-3c3e3a543f81"}]}You can copy and paste the entire page output from Excel to delete up to 500 documents from the tenant at a time.
-
Click Send
The documents are deleted and the response lists the number of documents deleted under 'RecordsDeleted'. If any of the selected documents are attached to a process, they will not be deleted and the number will be included under 'ExcludedDocuments' in the response.