I'm trying to upload an attachment i get from Outlook to a folder inside a SharePoint document library. I am Following the docs: https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http#http-request-to-upload-a-new-file
fetch(`https://graph.microsoft.com/v1.0/sites/${siteId}/drive/items/${parentId}:/${attachment.name}:/content`, {
method: 'PUT',
mode: 'cors',
headers: new Headers({
'Authorization': `Bearer ${accesToken}`,
'Content-Type': 'text/plain'
}),
body: attachment.contentBytes
})
All I get is an error with code: -1, Microsoft.SharePoint.Client.InvalidClientQueryException
I've tried setting the body of the fetch request as a simple string such as "hello world" with testing purposes and still get the same error.
Any ideas?
Thx in advance
[EDIT] I suspect I'm not building the URL right. I haven't found the documentation for the parameter:
- {item-id} I'm assuming this ID is the folder's
parentReference.siteId
attribute.
Is that right?
Entity only allows writes with a JSON Content-Type header.
– Kebin Liu