cameojbs
cameojbs

Reputation: 71

Getting error "invalidRequest" when creating upload session (Microsoft Graph Api)

I am getting the below error when creating upload session (Microsoft Graph Api).

{ "error": { "code": "invalidRequest", "message": "Invalid request", "innerError": { "request-id": "6e9cc58e-d3b9-456e-a794-90486969296e", "date": "2020-04-06T20:53:18" } } }

Post request https://graph.microsoft.com/v1.0/me/drive/root:/testapi:/createUploadSession

Request body :

Upvotes: 3

Views: 4965

Answers (3)

roboli
roboli

Reputation: 1478

Microsoft Graph API is a PITA. That said, this worked for me:

/drives/${driveId}/${childId}:/${filename}:/createUploadSession

If you are uploading to Sharepoint (instead of OneDrive), be sure to include only valid properties in the body payload (more here). This worked for me:

        {
            "item": {
                "name": "filename.txt"
            }
        }

Upvotes: 0

pradeepradyumna
pradeepradyumna

Reputation: 1072

I was implementing C# from here where the code was

var uploadSession = await graphClient.Me.Drive.Root
    .ItemWithPath(itemPath)
    .CreateUploadSession(uploadProps)
    .Request()
    .PostAsync();

In my case, I was able to fix it by updating itemPath by adding the full path to the file. For instance, if the path is

/RootFolder/Folder1

just update with file name like this

/RootFolder/Folder1/MyFile.pdf

Upvotes: 0

cameojbs
cameojbs

Reputation: 71

I have modified the request as below to make it work. See below :

POST https://graph.microsoft.com/v1.0/me/drive/items/01WCLVX5B7JBMYFMQKWNA3NVFODWCDUPGB:/3.pdf:/createUploadSession

Upvotes: 3

Related Questions