cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Flow Deleting old Versions on Sharepoint

Good day,

 

I have to run a flow each day to update datas. When I run them a new Version of the document is always created.

I have around 24 GB of Datas, Each File multiplied by 100. 
So I have 1,4 TB of data and my Storage is full.

 

MY QUESTION: Does anybody know how to delete all old Versions of a File in Sharepoint as it is not possible to set Versions to a lower Number then 100

 

Thanks


BRGDS
Jan Held

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Helper II
Helper II

Re: Flow Deleting old Versions on Sharepoint

I mean delete with FLOW!!!! not manually


@mardex wrote:

Good day,

 

I have to run a flow each day to update datas. When I run them a new Version of the document is always created.

I have around 24 GB of Datas, Each File multiplied by 100. 
So I have 1,4 TB of data and my Storage is full.

 

MY QUESTION: Does anybody know how to delete all old Versions of a File in Sharepoint as it is not possible to set Versions to a lower Number then 100

 

Thanks


BRGDS
Jan Held


 

View solution in original post

Highlighted
Community Support
Community Support

Re: Flow Deleting old Versions on Sharepoint

Hi @mardex,

 

Please refer to the following steps to delete the old versions of each file in the SharePoint library:

 

Step 1: Add Get files(properties only) action to get files in the list.

Step 2: Add Send an HTTP request to SharePoint

Method: GET
Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions

Annotation 2019-08-29 150852.pngStep 3: Parse JSON, put the body of the previous action into the Content of Parse JSON action, then click the button "Use sample payload" to generate schema to paste the following schema:

{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"uri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"CreatedBy": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"CheckInComment": {
"type": "string"
},
"Created": {
"type": "string"
},
"ID": {
"type": "integer"
},
"IsCurrentVersion": {
"type": "boolean"
},
"Length": {
"type": "string"
},
"Size": {
"type": "integer"
},
"Url": {
"type": "string"
},
"VersionLabel": {
"type": "string"
}
},
"required": [
"__metadata",
"CreatedBy",
"CheckInComment",
"Created",
"ID",
"IsCurrentVersion",
"Length",
"Size",
"Url",
"VersionLabel"
]
}
}
}
}
}
}

 

Annotation 2019-08-29 151226.png

Step 4: Create the other Send an Http request to SharePoint:

Method: DELETE
Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions(ID from the previous action)

Please have a try, I hope it can help you.

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Helper II
Helper II

Re: Flow Deleting old Versions on Sharepoint

I mean delete with FLOW!!!! not manually


@mardex wrote:

Good day,

 

I have to run a flow each day to update datas. When I run them a new Version of the document is always created.

I have around 24 GB of Datas, Each File multiplied by 100. 
So I have 1,4 TB of data and my Storage is full.

 

MY QUESTION: Does anybody know how to delete all old Versions of a File in Sharepoint as it is not possible to set Versions to a lower Number then 100

 

Thanks


BRGDS
Jan Held


 

View solution in original post

Highlighted
Super User
Super User

Re: Flow Deleting old Versions on Sharepoint

@mardex 

To delete old versions, you'll need to use the SharePoint HTTP action and call a SharePoint web service.  I can't provide the specifics, but that's the route you'll need to go.  Another way to approach this might be to create a new document (based on the old document including metadata) and delete the old one rather than updating the existing documents in your Flow.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Highlighted
Helper II
Helper II

Re: Flow Deleting old Versions on Sharepoint

thanks, I expected this. So it will be a hell of work for me as a non professional Smiley Sad


@ScottShearer wrote:

@mardex 

To delete old versions, you'll need to use the SharePoint HTTP action and call a SharePoint web service.  I can't provide the specifics, but that's the route you'll need to go.  Another way to approach this might be to create a new document (based on the old document including metadata) and delete the old one rather than updating the existing documents in your Flow.


 

Highlighted
Community Support
Community Support

Re: Flow Deleting old Versions on Sharepoint

Hi @mardex,

 

Please refer to the following steps to delete the old versions of each file in the SharePoint library:

 

Step 1: Add Get files(properties only) action to get files in the list.

Step 2: Add Send an HTTP request to SharePoint

Method: GET
Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions

Annotation 2019-08-29 150852.pngStep 3: Parse JSON, put the body of the previous action into the Content of Parse JSON action, then click the button "Use sample payload" to generate schema to paste the following schema:

{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"uri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"CreatedBy": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"CheckInComment": {
"type": "string"
},
"Created": {
"type": "string"
},
"ID": {
"type": "integer"
},
"IsCurrentVersion": {
"type": "boolean"
},
"Length": {
"type": "string"
},
"Size": {
"type": "integer"
},
"Url": {
"type": "string"
},
"VersionLabel": {
"type": "string"
}
},
"required": [
"__metadata",
"CreatedBy",
"CheckInComment",
"Created",
"ID",
"IsCurrentVersion",
"Length",
"Size",
"Url",
"VersionLabel"
]
}
}
}
}
}
}

 

Annotation 2019-08-29 151226.png

Step 4: Create the other Send an Http request to SharePoint:

Method: DELETE
Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions(ID from the previous action)

Please have a try, I hope it can help you.

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
New Member

Re: Flow Deleting old Versions on Sharepoint

Hi there,

 

Is it possible to set this up to on-demand remove all of the previous versions in a selected folder only, rather than daily automation for the whole library?

 

I would like to be able to select a project folder within a library once that project is completed, delete all the previous versions, keeping only the final files and then mark all files in that folder as read only so that no new versions are created if people then go and look at the files as reference for another project.

 

Many thanks

 

Chris

Many thanks

Helpful resources

Announcements
firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (7,203)