Microsoft Graph to create docx file

Yamilla Manjko 6 Reputation points
2022-10-07T13:43:34.613+00:00

I need to create a docx file, populate the content and sent it do OneDrive. Is it possible to create a docx file and set its content using Microsoft Graph api ou any other?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,839 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Shivam Dhiman 5,946 Reputation points
    2022-10-07T23:34:09.453+00:00

    Hi @Yamilla Manjko

    Using this PUT /me/drive/items/{parent-id}:/{filename}:/content Graph API you can create docx file, set its content and upload it to OneDrive.
    In body, select binary as format and attach file with content.

    Please refer to the below sample screenshot.
    248641-binary.png

    Please note: To upload large files you need to use Upload Session, Please refer to this documentation for more details.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. Yamilla Manjko 6 Reputation points
    2022-10-10T14:06:31.543+00:00

    Hi, @ShivamDhiman-1582! I appreciate the answer but the file needs to be generated through the API, it won't be an action from the user - basically, the user will click on a button, the system creates an HTML string with the formatted content, then we need to create a Docx file with this content and sent it to OneDrive - we can accomplish this today trough script but only with doc files, we need to be able to create Docx files as well so the user can edit the file on OneDrive.

    0 comments No comments