Sharepoint - Download and upload file from share point using Java (Rest API call)
For connecting to share point using rest Api 1st we need to request client id, client secret for a share point library.
Step 1 - once you got client id and secret follow steps mentioned at - https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/
to generate access token. using access token we can connect to share point using Rest Api or Java.
Download a file -
url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files('file name')/$value
method: GET
headers:
Authorization: "Bearer " + accessToken // what we got in step 1
Upload File : -
if your share point don't have any approval work flow then :-
url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='a.txt',overwrite=true)
method: POST
body: "Contents of file"
Headers:
Authorization: "Bearer " + accessToken
content-length:length of post body
If your share point library have approval work flow then we have to follow these steps: -
Step a) - upload file using Post request as I mentioned above
Step b) - check in last uploaded file using post request
url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/CheckIn(comment='Comment',checkintype=0)
method: POST
headers:
Authorization: "Bearer " + accessToken
Step c)- update approval status of recent uploaded file
follow this answer or post - https://sharepoint.stackexchange.com/a/253137/79002
Best blog to read :- https://blogs.sap.com/2018/02/01/consume-sharepoint-rest-to-create-a-file-using-java-sap-pi-udf/