Challenges during converting DOCX file to PDF on Azure App Service using MSGraph-SDK python

S,A 20 Reputation points
2024-10-15T20:36:44.1233333+00:00

Hi,

I tried Graph API (REST APIs via Postman) to convert DOCX files in my personal One Drive to PDF and it worked.

However, there are more things that did not work.

  1. I have tried using the msgraph-sdk Python SDK to convert the docx files. The PIP install itself failed as msgraph-sdk has super long filepaths. I had to enable longfilepath in the Windows Registry to complete the installation. On the other hand, pip install on Azure App Service (linux) had no errors.
  2. I wrote Python code to create MS graph client and convert docx file to PDF. Looks like I need some drive-id, drive-item-id, etc. to find and convert the files. I was unable to get these details for my personal one-drive files. While using the REST APIs, I used the GET API on URL: https://graph.microsoft.com/v1.0/me/drive/root:/Documents/my_file.docx:/content?format=pdf with Bearer token. Is there a similar Python API that can fetch and convert files using the file path instead of IDs?
  3. I am unable to find a programmatic way to give consent to read files from one-drive via Graph service. If it is possible, please provide some sample code. Also, will I need more permissions to download content in PDF format?
  4. Like I said, I was able to use the Graph REST APIs via Postman application to download docx files as PDFs, so I wrote a simple Python API to do the same using python's requests library, GET API and Authorization token in the headers. It worked in my local machine. But, when I deployed the API in my Azure App Service, it gives a NULL response. I see that the App Registration associated with Azure App Service, has API permission User.Read. Could you please help on this?

I understand my questions are too many. Please bear with me as I am confused connecting Azure and Office365 services together in one solution.

Microsoft Security Microsoft Graph
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.