What I am looking to do is upload a file to a Sharepoint subsite using the Graph API. I have been able to create a upload session and upload to a sharepoint site referencing https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online, however, when I try creating a session upload for a subsite on a sharepoint site I get an "itemNotFound" error code.
As an example, the url for creating an upload session for a file called example.txt is shown below
https://graph.microsoft.com/v1.0/sites/{hostname},{spsite-id},{spweb-id}/drive/items/{item-id}:/example.txt:/createUploadSession
where {hostname},{spsite-id},{spweb-id} is the ID of the sharepoint site (see https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0 for an overview of sharepoint sites in the Graph API) and {item-id} is the driveItem ID for the folder on sharepoint that we want to upload to. Before we use a POST request with the url, we need to include a request body in a json format (as shown in the first link) and below is what that should be at a minimum
{"item": {
"name": "example.txt"
}
}
Doing what I have described above, this works for creating an upload session on a sharepoint site (see the first link for using the upload session url). For a subsite on a sharepoint site, this is what I tried and it did not work. In order to get the ID of the subsite, I used the url below as a GET request
https://graph.microsoft.com/v1.0/sites/{hostname},{spsite-id},{spweb-id}/sites
where {hostname},{spsite-id},{spweb-id} is the parent Sharepoint site ID. This url gives the subsites of a Sharepoint site and I was able to obtain the ID of the subsite that I wanted to upload to. When I use this ID (which is in the form {hostname},{spsite-id},{spweb-id}) with the url for creating an upload session, it fails.
My question is what is the correct url to create an upload session on a subsite? The documentation does not specify how to do this other than what I have already shown for a regular Sharepoint site. If someone could please help, it would be appreciated
Thanks