A shared package for reading and writing to SharePoint
Project description
MPR-sharepoint-utils
Installing the package
pipenv install mpr-sharepoint-utils
Once the package is installed, you can use it like this:
from sharepoint_utils.lib import SharePointUtils
Using the package:
- Useful methods are in the SharePointUtils class, which requires these arguments to connect to your SharePoint instance:
client_id
, the ID portion of your user (or service) account credentialsclient_secret
, the secret string of your user (or service) credentialssite_id
, the ID of the SharePoint site you wish to accesstenant
, the name of your organization (you can find this in a SharePoint URL, like "tenant.sharepoint.com")
FAQs
Q: How do I know what my site ID is?
A: First, get your access token with the first command below; then, plug that into the second command below to get your site ID.
Get access token (can use to get site id given hostname and path (site/subsite)):
curl --location --request POST 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=INSERT_CLIENT_ID' \
--data-urlencode 'scope=https://graph.microsoft.com/.default' \
--data-urlencode 'client_secret=INSERT_CLIENT_SECRET' \
--data-urlencode 'grant_type=INSERT_CLIENT_CREDENTIALS'
Get site ID
curl --location --request GET 'https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id' \
--header 'Authorization: Bearer access_token' \
--data
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.