Conversion of pptx to jpg via graph API only returns the 1st page

Nemyrovska, Maryna 20 Reputation points
2024-09-19T10:13:42.3166667+00:00

Dear Sir or Madam,

as noted in the documentation, the conversion of pptx to jpeg is supported by Graph API. https://learn.microsoft.com/en-us/graph/api/driveitem-get-content-format?view=graph-rest-beta&tabs=http

However, when I convert it to jpg, I only retrieve a single image of the 1st slide. Please, see the code attached.

content_stream = None
url = f"https://graph.microsoft.com/v1.0/sites/{sharepoint_id}/drive/items/{document_id}/content?format=jpg&width=800&height=800"
headers = {'Authorization': 'Bearer ' + access_token}
response = requests.get(url, headers=headers, timeout = 1000000)#, timeout = 10) # in minutes, default 30 sec
print(response.status_code)
print(response.content)
if response.ok:
    content_stream = BytesIO(response.content)
content_stream

I have also tried to specify the page or slide, but it is hard to guess which variable needs to be sent, as there is not good documentation on working with jpg.

This is what I have tried:

url = f"https://graph.microsoft.com/v1.0/sites/{sharepoint_id}/drive/items/{document_id}/content?slide=10&format=jpg&width=1200&height=1200"
url = f"https://graph.microsoft.com/v1.0/sites/{sharepoint_id}/drive/items/{document_id}/content?page=10&format=jpg&&width=1200&height=1200"

I have thoroughly researched the documentation https://github.com/microsoftgraph/microsoft-graph-docs-contrib/blob/main/api-reference/beta/resources/driveitem.md but I could not find an answer there or in the linked documents.

Could you please give me an exact answer how can I get more than 1 slide of pptx converted to jpeg with a code example, e.g. url format or link to the code example.

Best regards,
Maryna

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

1 answer

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 240 Reputation points Microsoft Vendor
    2024-09-19T13:13:45.8333333+00:00

    Hi Nemyrovska, Maryna,

    The API to get /content?format=jpg is still under the /beta version in Microsoft Graph, which are subject to change. Use of these APIs in production applications is not supported.

    Additionally, please refer the below doc for supported content format for v1.0 of API.
    https://learn.microsoft.com/en-us/graph/api/driveitem-get-content-format?view=graph-rest-1.0&tabs=http#format-options

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

    0 comments No comments

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.