Reputation: 1
I am attempting to access a SharePoint site using the Microsoft Graph API from a Python script. Despite having granted the necessary permissions in Azure AD and assigning licenses, I keep encountering the following error:
Failed to get site ID. Status code: 400
{
'error': {
'code': 'BadRequest',
'message': 'Tenant does not have a SPO license.',
'innerError': {
'date': '2024-05-22T12:52:33',
'request-id': 'cd207c1f-5bbc-435d-b6e3-94170d9e6aff',
'client-request-id': 'cd207c1f-5bbc-435d-b6e3-94170d9e6aff'
}
}
}
Azure AD App Registration:
SharePoint Permissions:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>
Licenses:
Python Script:
Upvotes: 0
Views: 412
Reputation: 2869
The "Tenant does not have a SPO license" error is normally given on a tenant which has no OneDrive for Business or SharePoint Online (SPO) subscription. Please check that you've logged in with the correct user id.
Make sure that you're not using a Microsoft 365/Office 365 Home license, as that will give the same error message.
If you're sure that you have the correct subscription, try every call to the Microsoft Graph using the Microsoft Graph Explorer before you start writing any code.
Attempt to call the API for the root site first:
https://graph.microsoft.com/v1.0/sites/root
Notice that the root site has an ID of something like this:
m365x214355.sharepoint.com,5a58bb09-1fba-41c1-8125-69da264370a0,9f2ec1da-0be4-4a74-9254-973f0add78fd
That's a site hostname and 2 IDs comma separated.
Any calls to a particular site will be in this format, so this:
https://graph.microsoft.com/v1.0/sites/:siteId/drives
becomes this:
https://graph.microsoft.com/v1.0/sites/m365x214355.sharepoint.com,5a58bb09-1fba-41c1-8125-69da264370a0,9f2ec1da-0be4-4a74-9254-973f0add78fd/drives
This gives a list of the drives (including the document repository) for the site.
From there you can further query the Microsoft Graph.
Also, you need the driveItem ID for your "Document_Repository" rather than it's name /title.
Upvotes: 0