Not able to convert .docx file to pdf using microsoft graph api - microsoft-graph-api

For my project need, I need to convert MS format documents in to pdf. I started exploring microsoft graph API. For easiness I started with graph explorer(using my corporate and personal login) on https://developer.microsoft.com/en-us/graph/graph-explorer.
I have added sample document in drive and using https://graph.microsoft.com/v1.0/me/drive/root/children, I got itemId of my file.
Now, I am trying to convert it into pdf using https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf. But I am always getting response as Failure - Status Code 0
Anyone has an idea how to fix this issue?
Here is an attached screen shot of microsoft graph explorer
Note: I found similar problem here but it is not solved

According to your description, I assume you want to convert .docx file to pdf using Microsoft graph API.
Based on my test, we can use https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf.
It will return a failure response when run it in graph explore. However, when we use the develop control panel, we can get this request and response.
Location properties are in the response headers. It is the address of the converted file.
We can use this URI to review or download the document that converted.
The request URL:
https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf
The response may like this:

Related

Microsoft Graph support for editing open PowerPoint files

I have a scenario where the user's open PowerPoint presentation needs to be modified by a custom solution. I'm looking at using a PowerPoint web add-in in conjunction with the Graph API's support for OneDrive/SharePoint files.
However, PowerPoint has nothing specifically available in the JavaScript for Office API yet for replacing the contents of the actively edited presentation. As a proof of concept, I've tried using Graph to overwrite a specific PowerPoint file in OneDrive using the upload command, but it throws an error because the file is open in PowerPoint for Windows:
Status Code: 423 Microsoft.Graph.ServiceException: Code: resourceLocked
Message: The resource you are attempting to access is locked
Inner error: AdditionalData:
date: 2020-10-05T21:06:53
request-id: 5e3c2604-382d-4139-a433-8b95ef4f619e
client-request-id: 5e3c2604-382d-4139-a433-8b95ef4f619e
ClientRequestId: 5e3c2604-382d-4139-a433-8b95ef4f619e
I note that if I open that same file in PowerPoint Online, the sharing icon indicator triggers and I'm able to make changes in either editor that are nearly immediately updated in the other editor. So a protocol exists for making live changes. I'm guessing this is through WOPI??. Is there another Graph method available I can use that can support this scenario? Or do I have to build a full WOPI client and/or server solution to do this (which looks insane, if it's possible)?

Unable to set profile picture using Graph Explorer

I'm trying to update my profile picture using Microsoft Graph Explorer (v1.0) but I'm unable to do it, I'm always getting the following error :
An internal server error occurred. The operation failed., The file you chose isn't an image. Please choose a different file.
The problem is that the file I'm trying to update my picture with is an image inserted in the request body (a base64 representation of it, I used this site in order to get it: https://www.base64-image.de/).
I'm also using the header Content-Type with the value image/jpeg and I think that, as I'm logged, I don't need the authorization header.
The URL I'm using is: https://graph.microsoft.com/v1.0/me/photo/$value
This endpoint takes the raw image as input, not a base64 encoded version. From the documentation:
Request body
In the request body, include the binary data of the photo in the request body.
Since it isn't possible to stream a file like this using Graph Explorer, updating the photo isn't supported by Graph Explorer.

Node.js - Download .docx file exported as html from onedrive using microsoftgraph api call

When making a call like this example from here
client
.api('/me/drive/root/children/Doc.docx/content')
.getStream((err, downloadStream) => {
let writeStream = fs.createWriteStream('Mydoc.docx');
downloadStream.pipe(writeStream).on('error', console.log);
});
It works as expected. What I want is to get the .docx file as html. Is there any way to download it in html format? Or do I have to save the file and then try to export it to html. Thanks
Word Documents (.docx) do not use HTML, they use Office Open XML (OOXML). Technically they are a zipped package that contains several elements along with the raw OOXML of the document.
OneDrive itself does not provide any document conversion tools, it is just the cloud storage the document is stored in.
In order to convert a document from one format to another (OOXML to HTML for example), you'll need to use a 3rd party tool or service for that purpose. I'd suggest taking a look as Aspose. They offer a slew of file format conversion tools including one for Word. I've had a number of developers report good results using their Aspose Cloud services as well.
You can add the query parameter format=html to download in html format but supposedly you have to use the beta endpoint.

Google Fusion Tables upload

Trying to follow instructions from google and upload a csv for a new fusion table. The page throws a very helpful error 'Import failed. Please retry.', and the dev console shows the server actually returned an http 405 error 'HTTP method POST is not supported by this URL'
page:
https://fusiontables.google.com/DataSource?dsrcid=implicit
Is there another way to upload csv files?
Your link suggests that you're trying to upload a 228mb file. I think I had some issued with large CSVs too. You could cut it up into smaller files until the error goes away, but IIRC the maximum file size is something like 5mb.
My preferred work-around is importing via Google Sheets. Upload your CSV to Drive, re-save it from Sheets, then import the Sheet into Fusion Tables.

Get the Id of Office365 for the file API from SharePoint REST API

I'm working on an iOS app using the Office365 iOS SDK.
I'm also using the SharePoint REST API to search for files in the Office 365 SharePoint/OneDrive files. The search call looks like this:
.../search/query?querytext='myQuery'&SelectProperties='UniqueId,Title,Path,Size,Author'
The search works fine and gives me results. Now I want to download files from the search results. For this I am using the Office iOS SDK. To download a file, I need the ID of the file, as described here: https://msdn.microsoft.com/office/office365/APi/files-rest-operations#FileoperationsDownloadafileREST
In the iOS SDK, there's this corresponding method:
spClient.getfiles().getById(fileID)
The problem is, how do I get this fileID from the search REST API? I tried UniqueID but that doesn't work. Is there any way to get this ID?
UniqueId isn't a property of a File/Folder object. Selecting Id will return what you want. For reference, here are the properties of a File/Folder object.
EDIT: Here's the request I made to test this. GET /_api/v1.0/me/files?$select=id,name,size HTTP/1.1. Without pasting the entire response, I'll say I got what's expected, an array of File/Folder items with the ID, name, and size properties. Please let me know if you need more help!

Resources