Skip to content

GetFileByServerRelativeUrl fails with nondescriptive error on files with only one version #10444

@tomacPA

Description

@tomacPA

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

SharePoint REST API

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

Calling the SP API via the Power Automate action "Send an HTTP request to SharePoint"

Describe the bug / error

Using the following URI:
https://tenant.sharepoint.com/teams/LibraryName/_api/web/GetFileByServerRelativeUrl('/teams/LibraryName/Shared%20Documents/General/TestFile.txt')/versions(512)/$value

The API call fails with the following error:
"body": { "status": 400, "message": "Cannot write the value 'null' in raw format.\r\nclientRequestId: 69c173cf-acca-422b-9f3a-79a83616ddb7\r\nserviceRequestId: 099cd1a1-10af-a000-801f-818442e1a307", "source": "https://tenant.sharepoint.com/teams/LibraryName/_api/web/GetFileByServerRelativeUrl('/teams/LibraryName/Shared%20Documents/General/TestFile.txt')/versions(512)/$value", "errors": [ "-1", "Microsoft.Data.OData.ODataException" ] }

This failure only occurs on files that do not have multiple versions, in other words where the version in the library is the original upload. It works as expected in the same folder for files with multiple versions.

When running automation to gather v1.0 files in a directory, the API will work on files with multiple versions and fail on files where v1.0 is the only version.

Steps to reproduce

  1. Have a SP directory with files that have multiple versions and files that are the original upload with no subsequent versions
  2. Run a script that gathers a list of the files in the directory, then loops through each file calling this API to get v1.0 of each file
  3. Observe returned values from API calls are failures for files without multiple versions

Expected behavior

Expected behavior would be to return file content for all v1.0 files even if v1.0 is the only version.

Metadata

Metadata

Assignees

Labels

area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIsharepoint-developer-supportsharepoint-developer-supporttype:bug-confirmedConfirmed bug, not working as designed / expected.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions