I am creating a python script that needs to create Folder Directories, and upload files into a SharePoint sub-site document library. I currently am using Sharepy for authentication, and the REST API for the requests.
Oddly enough, posting to the main SharePoint site works successfully. I am authorized to upload files and create folders without an issue. When I move to sub-sites using the API call similar to below:
p = s.post("https://"+SPUrl+"/sites/"+siteName+"/_api/web/folders",
json={
"__metadata": { "type": "SP.Folder" },
"ServerRelativeUrl": libraryName +'/' +destFolder[-1]
})
(where s is the sharepy object) I get an access denied message.
For reference, the credentials used are that of a global administrator, or SharePoint administrator. And both work at the main site.
Below is also how I am looking to upload a singular file:
p = s.post(f"https://{SPUrl}/sites/{siteName}/_api/web/GetFolderByServerRelativeUrl('{libraryName}/{destFolder[-1]}')/Files/add(url='{fileToUpload}',overwrite=true)", data=content, headers=headers)
I have done a lot of research and searched forums, but nothing that I have found seems remotely similar to my issue.
I am very new to SharePoint and the REST API, and any help in resolving my issue would be most appreciated.
My Question: How exactly do I connect to a SharePoint sub-site using the REST API in order to upload documents and create Files. In my code I attempt to do this but get privilege errors regardless of success in the main site. I would like to know if my code is invalid, or perhaps there are restrictions on what you can do with sub-sites. (or a special setting that might need to be changed on SharePoint's side.)