How to Check In Check Out and Upload File on Sharepoint using cURL and OAUTH token

209 Views Asked by At

I want to share below solution for CheckOut , Upload File and CheckIn on Sharepoint using cURL

#Excel CheckOut

curl -k --data '' --request POST -H "oauth2TokenHeader" "https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder/FileName.xlsx')/CheckOut()"

#Upload File

curl -k --data '' --request PUT -H "oauth2TokenHeader" "https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder/FileName.xlsx')/$value" --upload-file C:\Filename.xlsx

#Excel CheckIn

curl -k --data '' --request POST -H "oauth2TokenHeader" "https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder/FileName.xlsx')/CheckIn(comment='comment',checkintype=1)"

--data '' = for Content-Length 0 -k=skip certificate validation -H=a command line option for the curl command that takes a single parameter of an extra header to include in the request

checkintype=1 for Major Version Update checkintype=0 for Minor Version Update

oauth2TokenHeader if using OAUTH2 then use the tokenheader otherwise use username/password instead

Use below link for more guide

https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest

Solution works great I hope it help others.

0

There are 0 best solutions below