-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathcreate.py
More file actions
27 lines (19 loc) · 937 Bytes
/
Copy pathcreate.py
File metadata and controls
27 lines (19 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Create a modern page on a SharePoint site.
https://learn.microsoft.com/en-us/sharepoint/dev/apis/site-pages-api-reference
"""
import argparse
import uuid
from office365.sharepoint.client_context import ClientContext
from tests.settings import cert_path, cert_thumbprint, client_id, team_site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Create a modern page")
parser.add_argument("--site-url", default=team_site_url, help="target site URL")
parser.add_argument("--title", default=f"Name{uuid.uuid4().hex[:8]}", help="page title (default: generated)")
args = parser.parse_args()
ctx = ClientContext(args.site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
page = ctx.site_pages.create_page(args.title).execute_query()
print(f"Page created: {page.absolute_url}")
if __name__ == "__main__":
main()