1

So I have a document library at https://tenant.sharepoint.com/sites/Test/Documents/

and I have a document in it called Doc1.docx. It has an Item Id of 1.

I use the following rest call in a browser to get the id of the list item associated with the document

https://tenant.sharepoint.com/sites/Test/_api/web/getFileByServerRelativeUrl('/sites/Test/Documents/Doc1.docx')/listItemAllFields?$select=Id,Title

As expected it comes back with the proper list item id of one.

Now I go and delete Doc1.docx from the library, and then upload it again. Now the Doc1.docx has the item Id of 2, right?

I use the same rest call to get the Id of the list item associated with the document

https://tenant.sharepoint.com/sites/Test/_api/web/getFileByServerRelativeUrl('/sites/Test/Documents/Doc1.docx')/listItemAllFields?$select=Id,Title

It still says the list Item ID is still one.

As a workaround I ended up including the 'Modified' field in the $select parameter. This makes it return the proper results.

Update : this workaraound stopped working. Now I got it working by leaving off the # select.

Also note that I am generating these rest calls with-pnp-js-core. Not that that should male any difference:

return pnp.sp.web.getFileByServerRelativeUrl(results.data.ServerRelativeUrl).getItem<{ Id: number, Title: string, Modified: Date }>("Id", "Title", "Modified").then((item) => {

Is this the expected behaviour of getFileByServerRelativeUrl or is this a bug?

  • Maybe the ajax call was cached...? – Mike May 23 '17 at 17:08
  • I'm pretty sure I checked it in fiddler, let me double check that. – russellg May 23 '17 at 20:12
  • 1
    yep, fiddler shows sharepoint online is returning HTTP/1.1 304 Not Modified, when, in fact, I deleted and upload a new version of the file. Worse yet, my workaround stopped 'working around the issue. – russellg May 23 '17 at 20:32
2

For similar ajax calls to SP REST API try use noncache factor on your request url. Example:

https://tenant.sharepoint.com/sites/Test/_api/web/getFileByServerRelativeUrl('/sites/Test/Documents/Doc1.docx')/listItemAllFields?$select=Id,Title + "?" + new Date().getTime()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.