Reputation: 1191
I am integrating OneDrive for business (REST API) with our Platform. I can upload a file and update the files contents using the upload API. But how do I get the revision history of a file. The API which I am using is listed below.
Upvotes: 1
Views: 630
Reputation: 345
You can't use OneDrive for business API to get file revisions (versions), but you can use SharePoint API to get them.
Use this link to get file versions:
where:
"email_tenant_onmicrosoft_com" - is email of your drive
"tenant-my.sharepoint.com" - EndPoint of your drive
Response of this link looks like this JSON:
{
"odata.metadata": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/$metadata#SP.ApiData.FileVersions",
"value": [
{
"odata.type": "SP.FileVersion",
"odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersionf1111111-aaaa-1234-5678-90abcdef1234",
"odata.editLink": "SP.FileVersionf1111111-aaaa-1234-5678-90abcdef1234",
"CheckInComment": "",
"Created": "2013-04-27T15:57:57Z",
"ID": 512,
"IsCurrentVersion": false,
"Length": "5716",
"Size": 5716,
"Url": "_vti_history/512/Documents/TEST_005.xlsx",
"VersionLabel": "1.0"
},
{
"odata.type": "SP.FileVersion",
"odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersion2ab46e3e-9614-43ff-ad03-252b1f4d0d90",
"odata.editLink": "SP.FileVersion2ab46e3e-9614-43ff-ad03-252b1f4d0d90",
"CheckInComment": "",
"Created": "2013-04-27T15:58:39Z",
"ID": 1024,
"IsCurrentVersion": false,
"Length": "7868",
"Size": 7868,
"Url": "_vti_history/1024/Documents/TEST_005.xlsx",
"VersionLabel": "2.0"
},
{
"odata.type": "SP.FileVersion",
"odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersion42f5f367-05ca-4131-84bf-79e7a6c0f77d",
"odata.editLink": "SP.FileVersion42f5f367-05ca-4131-84bf-79e7a6c0f77d",
"CheckInComment": "",
"Created": "2013-04-27T15:58:43Z",
"ID": 1536,
"IsCurrentVersion": false,
"Length": "7868",
"Size": 7868,
"Url": "_vti_history/1536/Documents/TEST_005.xlsx",
"VersionLabel": "3.0"
}
]
}
important parameters for you is:
"odata.editLink" after "SP.FileVersion" - it's unique Id of file version. "ID" - it's version id of current file.
To download file version you can use this link:
where "1024" - field "ID" from JSON.
To get info about last version of item you can use this link:
Response of this link looks like this JSON:
{
"odata.metadata": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/$metadata#SP.ApiData.Files12/@Element",
"odata.type": "SP.File",
"odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/Web/GetFileByServerRelativeUrl('/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx')",
"odata.editLink": "Web/GetFileByServerRelativeUrl('/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx')",
"CheckInComment": "",
"CheckOutType": 2,
"ContentTag": "{C4B73433-8AED-44C2-862A-746EBA4599EB},11,7",
"CustomizedPageStatus": 0,
"ETag": "\"{C4B73433-8AED-44C2-862A-746EBA4599EB},11\"",
"Exists": true,
"IrmEnabled": false,
"Length": "7923",
"Level": 1,
"LinkingUri": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx?d=wc4b734338aed44c2862a746eba4599eb",
"LinkingUrl": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx?d=wc4b734338aed44c2862a746eba4599eb",
"MajorVersion": 4,
"MinorVersion": 0,
"Name": "TEST_005.xlsx",
"ServerRelativeUrl": "/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx",
"TimeCreated": "2013-04-27T15:57:55Z",
"TimeLastModified": "2013-04-27T15:59:28Z",
"Title": null,
"UIVersion": 2048,
"UIVersionLabel": "4.0",
"UniqueId": "c4b73433-8aed-44c2-862a-746eba4599eb"
}
you can use this info, when you add a new revision of file.
"UniqueId" - it's right part of "odata.editLink" in versions JSON. "UIVersion" - it's "ID" in version JSON.
To download last version of file - use this link:
link:
doesn't work. It will work if you add a new version of this file.
You can download last revision of item by using OneDrive API link:
but this link doesn't work if you use Service Account authentication
Upvotes: 1
Reputation: 130
Till date there is no api resource for getting version or revision history of a file. Follow the link to know about available operations on items in one drive for business.
Upvotes: 0