1

I am trying to use REST to update a list item but the library has forced check out enabled.

Does this mean I need to make 3 rest calls for each item I was to update?

  • The S in REST is for State.. the "State" an object is in (on the Server) You are changing that "State" 3 times: CheckedOut, New Version, CheckedIn. Since there can be an X amount of time between the States, that means you have to do 3 REST calls (so any requests from others always get the correct "State") – Danny '365CSI' Engelman Apr 22 '17 at 11:38
3

Yes, you need to make 3 REST calls. One for checking out the item, second for updating the item, third for checking in the item.

I presume you know that you actually need to make another REST call before all these 3, a call to retrieve the Form Digest Value from the context info of the site where the item is located.

The REST URI structure for checkouts and checkins looks like this:

  • Check out: http:///_api/web/GetFileByServerRelativeUrl( '/Shared Documents/a.txt')/CheckOut()
  • http:///_api/web/GetFileByServerRelativeUrl( '/Shared Documents/a.txt')/CheckIn(comment='your_comments_here', checkintype=#)

The # in the second bullet point is a number from 0 to 2, where 0 = Minor Version, 1 = Major Version, 2 = Overwrite the current version.


UPDATE It seems the question was for SharePoint 2016, while I was presuming it was for the SharePoint 2013.

SharePoint 2016 (Office 365 as well) supports making batch requests with REST APIs. SO instead of 3 calls, you can make only one. See this MSDN article.


References:

  • Thank you for the comprehensive answer. I'll get the requet digest from the page i'm on so that should be fine. It's a little annoying building 3 calls per file to update 1 property. I might actually move it to use JSOM and do it as a bulk operation instead. – Batman Apr 22 '17 at 17:11
  • Yeah, unfortunately only SP Online and SP 2016 support batching REST calls. See msdn.microsoft.com/en-us/library/office/dn903506.aspx - do not get confused over the fact the this article says it applies to SP 2013 as well because it does not. It actually refutes itself in the first paragraph. JSOM will definitely help you here to batch all calls into one if your scenario allows it. – Mihail Popa Apr 22 '17 at 18:26
  • Well I am on 2016 so maybe this would work. Good idea. I'm trying to update multiple items at once and I'd like to use promises which is why I like REST since I can just put through all the promises in an array and deal with the end result. I think I can do the same with JSOM, I just don't know how right now so if I can use batch rest I might explore that further. – Batman Apr 22 '17 at 18:48
  • Oh, my bad. It did not occur to me that I assumed you work with SP2013. In this case, yes,you should definitely batch your REST calls. I will update my answer. – Mihail Popa Apr 23 '17 at 11:53

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.