-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_template.py
30 lines (22 loc) · 1.16 KB
/
metadata_template.py
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
from boxsdk import BoxAPIException, JWTAuth, Client # Box API
from boxsdk.object.metadata_template import MetadataField, MetadataFieldType
from boxsdk.object.search import MetadataSearchFilter, MetadataSearchFilters
import secret_credentials # For generating the iamtesttoken
url_base = 'https://eis.identity.ucsb.edu/.'
headers = { "Authorization" : 'Bearer {}'.format(secret_credentials.generate_iamtesttoken()) }
config = JWTAuth.from_settings_file('PROD_config.json')
client = Client(config)
service_account = client.user().get()
print(f'Service Account user ID is {service_account.id}')
print("Attempting to create metadata template")
try:
templates = client.get_metadata_templates()
for template in templates:
print(f'Metadata template {template.templateKey} is in enterprise scope')
fields = [
MetadataField(MetadataFieldType.STRING, 'drawer_name'),
]
template = client.create_metadata_template('FolderMetadata', fields, hidden=False)
print(f'Metadata template ID {template.scope}/{template.templateKey} created!')
except:
print("Unable to create Metadata template (may already exist)")