Forum Discussion
mmoales
8 years agoIdeator II
Hi Chris,
That worked perfect for the delete. To create the relationship, I am first locking the Document, creating the Document File relationship, querying the Document for its new ID, and then unlocking the Document:
def attach_file(s, keyed_name, fileId, item_id, item_type='Document', rel_type='Document File'):
# lock
data = { '@aras.action': 'lock' }
r = s.post(
host + "/InnovatorServer/Server/odata/{0}('{1}')".format(item_type, item_id),
headers = REST_HEADERS,
data=json.dumps(data))
r.raise_for_status()
# Create relationship
data = { '[email protected]': "File('{0}')".format(fileId) }
r = s.post(
host + "/InnovatorServer/Server/odata/{0}('{1}')/{2}".format(item_type, item_id, rel_type),
headers = REST_HEADERS,
data=json.dumps(data))
r.raise_for_status()
# Get the updated item
r = s.get(
host + "/InnovatorServer/Server/odata/{0}?$filter=keyed_name eq '{1}'".format(item_type, keyed_name),
headers = REST_HEADERS)
r.raise_for_status()
item_id = r.json()['value'][0]['id']
# Unlock
data = { '@aras.action': 'unlock' }
r = s.post(
host + "/InnovatorServer/Server/odata/{0}('{1}')".format(item_type, item_id),
headers = REST_HEADERS,
data=json.dumps(data))
r.raise_for_status()
Is there a cleaner way to do this?
Thanks,
Mark