#๐Ÿ”’ Microsoft Graph SDK - Getting OneNote Notebook data

4 messages ยท Page 1 of 1 (latest)

glass marlin
#

Im trying to write a script/small app that goes through a notebooks sections, creates a folder on the machine thats running the script for every section and saves the section's pages' html in their respective folder (basically so i can import them to confluence or whatever else).
I cant figure out how to access this data, because im using the code snippets from graph explorer and all im getting is 400 and bad request errors.
Id appreciate some help and maybe some docs on how to leverage the client classes from the msgraph-sdk.

import asyncio
import configparser
from msgraph import GraphServiceClient

from azure.identity.aio import ClientSecretCredential

# Read configuration from .cfg file
config = configparser.ConfigParser()

config.read("config.cfg")

# Get Azure configuration values
azure_config = config["azure"]
client_id = azure_config["clientId"]
tenant_id = azure_config["tenantId"]
secret_id = azure_config["clientSecret"]

credentials = ClientSecretCredential(
    tenant_id=tenant_id, client_id=client_id, client_secret=secret_id
)
scopes = ["https://graph.microsoft.com/.default"]
client = GraphServiceClient(credentials=credentials, scopes=scopes)


async def main():
    apps = await client.applications.get()
    if apps and apps.value:
        for app in apps.value:
            print(app.display_name)
    # Gets registered app name as expected

    await client.me.onenote.pages.by_onenote_page_id(
        "0-e4480296df44483797a6e9498a27ee08!240-2D4AD3C4F6B959E4!363379",
    ).content.get()
    # 400 Bad request
    # msgraph.generated.models.o_data_errors.o_data_error.ODataError:
    # APIError
    # Code: 400
    # message: None


asyncio.run(main())

late locustBOT
#

@glass marlin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

late locustBOT
#

@glass marlin

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.