# msgraph-sdk > Microsoft Graph SDK + M365 Copilot API access. Use when the user needs to interact with Microsoft 365 services: (1) Email - read, send, search, organize messages, (2) Calendar - events, meetings, invitations, (3) Tasks - Microsoft To Do lists and tasks, (4) Files - OneDrive operations, (5) OneNote - notebooks, sections, pages, (6) Contacts - Outlook contacts, (7) Search - M365 content search, (8) Copilot Retrieval - search across SharePoint/OneDrive using Copilot API. Provides direct SDK access for ANY Graph API operation with full control over requests. - Author: Martin DaRosa - Repository: martindrq/personal_agent - Version: 20251221210234 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-07 - Source: https://github.com/martindrq/personal_agent - Web: https://mule.run/skillshub/@@martindrq/personal_agent~msgraph-sdk:20251221210234 --- --- name: msgraph-sdk description: "Microsoft Graph SDK + M365 Copilot API access. Use when the user needs to interact with Microsoft 365 services: (1) Email - read, send, search, organize messages, (2) Calendar - events, meetings, invitations, (3) Tasks - Microsoft To Do lists and tasks, (4) Files - OneDrive operations, (5) OneNote - notebooks, sections, pages, (6) Contacts - Outlook contacts, (7) Search - M365 content search, (8) Copilot Retrieval - search across SharePoint/OneDrive using Copilot API. Provides direct SDK access for ANY Graph API operation with full control over requests." --- # Microsoft Graph SDK + M365 Copilot API ## Overview Direct access to Microsoft Graph SDK (Python) and M365 Copilot Retrieval API. Execute any Graph API operation with full control. For any search task (emails, files, notes, events, chat messages, etc.), always use the M365 content search. Is better to find things. See m365-copilot-usage.md for know how to use it. For notes always use the onenote notebook "PersonalDB" ## Workflow 1. **Authenticate** (if needed): `python auth.py login` 2. **Consult Context7** for SDK syntax: `ask_question(repo="microsoftgraph/msgraph-sdk-python", question="...")` 3. **Execute code**: `python execute.py ""` 4. **For Copilot**: `python execute.py --copilot ""` ## Authentication ```bash cd scripts # First time or token expired python auth.py login # Check status python auth.py check # Logout python auth.py logout ``` ## Execution ```bash python execute.py "" # Graph SDK python execute.py --copilot "" # With Copilot API python execute.py --file script.py # From file python execute.py "" --format json # JSON output ``` ### Examples - If you need to get the content and sections/pages of a .one file you can use: ```bash python onenote_explorer.py "https://martindrq-my.sharepoint.com/.../PersonalDB/Memoria/Hallazgos.one" ``` - If you need to search in Micrsoft 365 Copilot: ```bash python execute.py --copilot " from microsoft_agents_m365copilot_beta.generated.copilot.retrieval.retrieval_post_request_body import RetrievalPostRequestBody from microsoft_agents_m365copilot_beta.generated.models.retrieval_data_source import RetrievalDataSource body = RetrievalPostRequestBody() body.data_source = RetrievalDataSource.SharePoint body.query_string = 'your search query' result = await copilot_client.copilot.retrieval.post(body) for hit in (result.retrieval_hits or []): print(f'{hit.web_url}') for extract in hit.extracts: print(f' {extract.text}') " ``` ### Common errors ``` Exit code 1 ❌ Error: name 'graph_client' is not defined ``` Fix: the variable is client not graph_client