If I use the following code sample I am able to get my SharePoint Site entity which looks like this:
But the fields drive
or drives
which should contain the Drive entity of the Site entity (where there is the Document Library) are None
.
Also the lists
field is None
(AFAIK drives
are a special type of lists
with template "Document Library", so I expected to see everything here).
On the other hand, using the dashboard of my site directly I am able to upload/download files from the Document Storage:
import os
import jwt
from typing import Optional, Literal
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.folder import Folder
from msgraph.generated.drives.item.items.item.content.content_request_builder import ContentRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
from src.config.loader import CONFIG
import aiofiles
from src.utils.logger import get_logger
logger = get_logger(CONFIG.logging.name, CONFIG.logging.level)
class GraphClientSingleton():
_client = None
_credentials = None
@classmethod
def get_client(cls):
if cls._client is None:
# cls._authority = 'login.microsoftonline.com'
cls._credentials = ClientSecretCredential(
tenant_id = CONFIG.msgraph.tenant_id_sharepoint,
client_id = CONFIG.msgraph.client_id_sharepoint,
client_secret = CONFIG.msgraph.client_secret_sharepoint,
)
cls._scopes = ['https://graph.microsoft.com/.default']
cls._client = GraphServiceClient(credentials=cls._credentials, scopes=cls._scopes)
return cls._client
if __name__ == "__main__":
async def test_api():
sp_dao = SharePointDAO()
site_id = ... # my site id
site = await sp_dao.client.sites.by_site_id(site_id).get()
logger.info(site)
import asyncio
asyncio.run(test_api())
My questions are:
site_id
as information to crawl into the right resource?If you have siteId
, you can list all document libraries by calling
result = await graph_client.sites.by_site_id('site-id').drives.get()
or expand the drives
relationship
query_params = SiteItemRequestBuilder.SiteItemRequestBuilderGetQueryParameters(
expand = ["drives"],
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.sites.by_site_id('site-id').get(request_configuration = request_configuration)