-
-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathget.py
More file actions
35 lines (25 loc) · 1.07 KB
/
Copy pathget.py
File metadata and controls
35 lines (25 loc) · 1.07 KB
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
28
29
30
31
32
33
34
35
"""
Retrieve a content type by name or by id.
https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/csom/contenttype
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import cert_path, cert_thumbprint, client_id, site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Get a content type by name or id")
parser.add_argument("--name", help="Content type name")
parser.add_argument("--id", help="Content type id")
args = parser.parse_args()
if not args.name and not args.id:
raise SystemExit("Provide --name or --id")
ctx = ClientContext(site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
ct = ctx.web.content_types.get_by_name(args.name) if args.name else ctx.web.content_types.get_by_id(args.id)
ct.execute_query()
print(f"Name: {ct.name}")
print(f"Description: {ct.description}")
print(f"ID: {ct.id}")
print(f"String ID: {ct.string_id}")
if __name__ == "__main__":
main()