sapmentors / cds-scp-api

CDS Extension for SAP Cloud Platform API Consumption
MIT License
15 stars 5 forks source link

Provided headers are deleted before sending the request to Microsoft Graph (OAuth2) #5

Closed EdoB closed 2 years ago

EdoB commented 2 years ago

Problem explanation

In order to upload a large file via the MSGraph DriveItems REST API we need to send a custom header (Content-Range) with a PUT request. During the getAuthorizationHeader function the headers passed with the AxiosConfig object get erased by an initialization.

Code which exposes the problem

const cdsapi = require("@sapmentors/cds-scp-api");

const service = await cdsapi.connect.to('destination');

service.run({
      method: "PUT",
      url: 'https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337',
      headers: {
        "Content-Length": 41024,
        "Content-Range": 'bytes 0-41023/41024',
      },
      data: 'buffer-data-to-be-sent',
})

Microsoft Graph DriveItems doc for context https://docs.microsoft.com/it-it/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#upload-bytes-to-the-upload-session