Reputation: 1
I use Microsoft graph to create a web application that uploads files to OneDrive. File upload uses upload session. https://learn.microsoft.com/ja-jp/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
uploading a file fails if the upload destination account is a Business account.
The error that occurs is
{" error ": {" innerError ": {" code ":" invalidToken "}," code ":" unauthenticated "," message ":" This access token is not valid on this endpoint. "}}
.
However, it will succeed if the upload destination is a personal account By the way, the simple upload will succeed in both business and personal. Do you know if there are any measures?
The following is the upload procedure.
(1)
POST /me/drive/root:/sample.txt:/createUploadSession
Authorization: Bearer {bearer token}
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "rename",
"name": "sample.txt"
}
}
(2)response
HTTP/1.1 200 OK
Content-Type: application/json
{
"uploadUrl": "https://our-tenant-my.sharepoint.com/personal/our_tenant_onmicrosoft_com/_api/v2.0/drive/items/aaaa/uploadSession?guid='example'&path='example'&overwrite=False&rename=True&dc=0&tempauth=example",
"expirationDateTime": "2019-05-24T05:07:08.728Z"
}
(3) Upload bytes to the upload session
PUT https://our-tenant-my.sharepoint.com/personal/our_tenant_onmicrosoft_com/_api/v2.0/drive/items/aaaa/uploadSession?guid='example'&path='example'&overwrite=False&rename=True&dc=0&tempauth=example
(4) return error
HTTP/1.1 401
{"error":{"innerError":{"code":"invalidToken"},"code":"unauthenticated","message":"This access token is not valid on this endpoint."}}
By the way, in case of a personal account, uploadUrl of the response is
https://api.onedrive.com/rup/example/more~~~
Will be back.
I can upload with this path.
UploadUrl is different in the personal account and the business account, is this related to this error?
Is there a way to solve this problem?
Upvotes: 0
Views: 797
Reputation: 1
This problem has been resolved. The reason is that the HTTP client of the web application has rearranged the query parameter of the URL. I used faraday of Ruby on Rails, so I changed this.
Upvotes: 0
Reputation: 918
When using PUT don't send the token it's not accepted there.
Including the Authorization header when issuing the PUT call may result in a HTTP 401 Unauthorized response.
The Authorization header and bearer token should only be sent when issuing the POST during the first step. It should be not be included when issueing the PUT.
Upvotes: 1