Reference·Python SDK · bimworksPython

LinkedDataApi

Python SDK: the Linked data operations, 15 methods, each with its parameters, result and a complete example.

Python SDK · bimworks · class · 15 methods

Files, URLs, texts and identifiers linked to objects, which follow their objects to later Versions

Construct it with the client of the connect step: bimworks.LinkedDataApi(client). Each method is one operation of the API part, where it runs on its page.

MethodOperationDescription
add_link_targetsAddLinkTargetsLink an existing item to more objects
confirm_link_matchConfirmLinkMatchConfirm that a link to check is on the right object
delete_linked_dataDeleteLinkedDataDelete items from every object and Version
download_linked_dataDownloadLinkedDataThe content of one item, as uploaded
end_linkEndLinkEnd a link from a Version on
get_linked_dataGetLinkedDataOne item with its links and their trail across Versions
get_linked_data_countsGetLinkedDataCountsWhich objects of a Version have linked data
get_linked_data_policyGetLinkedDataPolicyWhat this server accepts as linked data
link_dataLinkDataLink files, URLs, texts or identifiers to objects of a Version
list_linked_dataListLinkedDataThe linked data on a Version
reattach_linkReattachLinkPut a link on another object from a Version on
replace_linked_dataReplaceLinkedDataReplace an item from a Version on
restore_linked_dataRestoreLinkedDataBring deleted items back
unlink_dataUnlinkDataTake links off their objects, on every Version
update_linked_dataUpdateLinkedDataEdit the title, description, category, validity or identifier system of an item

add_link_targets#

Python#
def add_link_targets(self, add_link_targets_request: AddLinkTargetsRequest) -> LinkedDataLinks

Link an existing item to more objects. The item is shared, never copied. A target the item is already linked to on that Version is left as it is. Needs read rights on the item and write rights on the model of version_uuid.

OperationAddLinkTargets · POST /openapi/linkeddata/AddLinkTargets
Scopelinks:write

Parameters#

NameTypeDescription
add_link_targets_requestAddLinkTargetsRequestrequiredThe request: its properties are those of the model, its JSON that of AddLinkTargets's request body.

Returns#

LinkedDataLinks — The item and the links made

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.AddLinkTargetsRequest.from_json(r"""
{
  "item_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>",
  "targets": [
    {}
  ]
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).add_link_targets(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

confirm_link_match#

Python#
def confirm_link_match(self, confirm_link_match_request: ConfirmLinkMatchRequest) -> ConfirmLinkMatchResult

Confirm that a link to check is on the right object. The check goes back to one pairing BIM.works was not sure of (an object matched by type and place after an upload, or the first of several objects with the link's GlobalId). That span becomes CONFIRMED, every later span the check stuck to becomes OK, and the pair is written as a compare pair override of the two Versions. version_uuid is a Version on which the link is marked CHECK. Needs write rights on the model.

OperationConfirmLinkMatch · POST /openapi/linkeddata/ConfirmLinkMatch
Scopelinks:write

Parameters#

NameTypeDescription
confirm_link_match_requestConfirmLinkMatchRequestrequiredThe request: its properties are those of the model, its JSON that of ConfirmLinkMatch's request body.

Returns#

ConfirmLinkMatchResult — The confirmed span and the link with its trail

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ConfirmLinkMatchRequest.from_json(r"""
{
  "link_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>"
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).confirm_link_match(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

delete_linked_data#

Python#
def delete_linked_data(self, delete_linked_data_request: DeleteLinkedDataRequest) -> DeleteLinkedDataResult

Delete items from every object and Version. Restorable for retention_days, after which the content is purged. Needs write rights on the item's model; the user who added an item may also delete it within 24 hours without them. An item already deleted is answered as deleted; nothing is changed when one is refused.

OperationDeleteLinkedData · POST /openapi/linkeddata/DeleteLinkedData
Scopelinks:write

Parameters#

NameTypeDescription
delete_linked_data_requestDeleteLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of DeleteLinkedData's request body.

Returns#

DeleteLinkedDataResult — The items deleted

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.DeleteLinkedDataRequest.from_json(r"""
{
  "item_uuids": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "reason": ""
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).delete_linked_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

download_linked_data#

Python#
def download_linked_data(self, download_linked_data_request: DownloadLinkedDataRequest) -> bytes

The content of one item, as uploaded. delivery: stream (the default) answers the content as the body: a file byte for byte as uploaded, with its media type and file name; a text whole; a URL or an identifier as text/plain. X-BimWorks-Sha256 carries the SHA-256 of a file or long text, ETag the same quoted.

OperationDownloadLinkedData · POST /openapi/linkeddata/DownloadLinkedData
Scopelinks:read

Parameters#

NameTypeDescription
download_linked_data_requestDownloadLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of DownloadLinkedData's request body.

Returns#

bytes — The content

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.DownloadLinkedDataRequest.from_json(r"""
{
  "item_uuid": "00000000-0000-0000-0000-000000000000",
  "delivery": "stream",
  "disposition": "attachment"
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).download_linked_data(request)

# 4. The result
with open("null", "wb") as file:
    file.write(result)
Python#
def end_link(self, end_link_request: EndLinkRequest) -> LinkedDataLinkResult

End a link from a Version on. The link stays on the older Versions and is neither shown nor followed from from_version_uuid on; unlike UnlinkData, the older Versions keep it. The Version must come after the one the link was made on (unlink it otherwise). Needs write rights on the model.

OperationEndLink · POST /openapi/linkeddata/EndLink
Scopelinks:write

Parameters#

NameTypeDescription
end_link_requestEndLinkRequestrequiredThe request: its properties are those of the model, its JSON that of EndLink's request body.

Returns#

LinkedDataLinkResult — The link with its trail

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.EndLinkRequest.from_json(r"""
{
  "link_uuid": "00000000-0000-0000-0000-000000000000",
  "from_version_uuid": "00000000-0000-0000-0000-000000000000"
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).end_link(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

get_linked_data#

Python#
def get_linked_data(self, get_linked_data_request: GetLinkedDataRequest) -> LinkedDataDetails

One item with its links and their trail across Versions. The item with every field, the links on the models the caller can read, and per link the spans of Versions it was followed over, oldest first. A deleted item is answered too, so it can be restored. With version_uuid the model is followed up to that Version first. replaces and replaced_by name the items of a replacement (ReplaceLinkedData), both ways.

OperationGetLinkedData · POST /openapi/linkeddata/GetLinkedData
Scopelinks:read

Parameters#

NameTypeDescription
get_linked_data_requestGetLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of GetLinkedData's request body.

Returns#

LinkedDataDetails — The item, its links and its replacements

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.GetLinkedDataRequest.from_json(r"""
{
  "item_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>"
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).get_linked_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

get_linked_data_counts#

Python#
def get_linked_data_counts(self, get_linked_data_counts_request: GetLinkedDataCountsRequest) -> LinkedDataCounts

Which objects of a Version have linked data. For colouring and markers in a viewer. What is on an object is what ListLinkedData shows there. The objects, those with a link to check, the objects per file family, one marker per object (its item count, the family most of its items have) and the Version's totals. include_later adds the objects whose only links were made on later Versions (later), never counted in the totals. Needs read rights on the model.

OperationGetLinkedDataCounts · POST /openapi/linkeddata/GetLinkedDataCounts
Scopelinks:read

Parameters#

NameTypeDescription
get_linked_data_counts_requestGetLinkedDataCountsRequestrequiredThe request: its properties are those of the model, its JSON that of GetLinkedDataCounts's request body.

Returns#

LinkedDataCounts — The objects with linked data

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.GetLinkedDataCountsRequest.from_json(r"""
{
  "version_uuid": "<version uuid of the first demo model>",
  "include_later": false
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).get_linked_data_counts(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

get_linked_data_policy#

Python#
def get_linked_data_policy(self) -> LinkedDataPolicy

What this server accepts as linked data. The file families with their allowed extensions, the extensions that are never accepted, the limits, the categories, the identifier systems and the URL schemes of this server. A client builds its file picker and its messages from it, so a file that would be refused is explained before it is sent.

OperationGetLinkedDataPolicy · POST /openapi/linkeddata/GetLinkedDataPolicy
Scopelinks:read

Parameters#

None: the operation takes no request.

Returns#

LinkedDataPolicy — The policy

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
# (GetLinkedDataPolicy takes no request)

# 3. The call
result = bimworks.LinkedDataApi(client).get_linked_data_policy()

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

link_data#

Python#
def link_data(self, request: str, file: Optional[List[bytes]] = None) -> LinkDataResult

Link files, URLs, texts or identifiers to objects of a Version. Creates one item per entry of items in the JSON request part and links each item to every target. The files are the file parts, in the order of the items entries whose kind is FILE (an entry may name its part by position with stream instead); an entry without a filename takes the part's file name. No new Version is made: each link follows its object to the later Versions of the model.

OperationLinkData · POST /openapi/linkeddata/LinkData
Scopelinks:write

Parameters#

NameTypeDescription
requeststrrequiredA JSON-encoded LinkDataSpec (version_uuid, targets, items)
fileList[bytes]optionalThe files, in the order of the FILE items

Returns#

LinkDataResult — One entry per item, linked or refused

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = r"""
{
  "version_uuid": "<version uuid of the first demo model>",
  "targets": [
    {}
  ],
  "items": [
    {
      "kind": "URL"
    }
  ]
}
"""

# 3. The call
result = bimworks.LinkedDataApi(client).link_data(request=request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

list_linked_data#

Python#
def list_linked_data(self, list_linked_data_request: ListLinkedDataRequest) -> LinkedDataList

The linked data on a Version. Every link shown on the Version, or only those on some objects, with the items they link. The links of the model are followed up to the Version first, so the answer is never out of date. items holds each item once; links one entry per object, with oid_here, how the link was found there (how) and its state.

OperationListLinkedData · POST /openapi/linkeddata/ListLinkedData
Scopelinks:read

Parameters#

NameTypeDescription
list_linked_data_requestListLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of ListLinkedData's request body.

Returns#

LinkedDataList — The items and the links on the Version

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ListLinkedDataRequest.from_json(r"""
{
  "version_uuid": "<version uuid of the first demo model>",
  "oids": [
    0
  ],
  "qids": [
    ""
  ],
  "include_orphaned": false,
  "include_deleted": false,
  "with_objects": false,
  "include_later": false,
  "kinds": [
    "URL"
  ],
  "categories": [
    ""
  ]
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).list_linked_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))
Python#
def reattach_link(self, reattach_link_request: ReattachLinkRequest) -> LinkedDataLinkResult

Put a link on another object from a Version on. The older Versions keep the object they had. From version_uuid on the link is on target (REATTACHED, OK), follows that object's GlobalId to later uploads, and the newer Versions are followed again from there. On the Version the link was made on, it corrects the object the link was made on. Needs write rights on the model.

OperationReattachLink · POST /openapi/linkeddata/ReattachLink
Scopelinks:write

Parameters#

NameTypeDescription
reattach_link_requestReattachLinkRequestrequiredThe request: its properties are those of the model, its JSON that of ReattachLink's request body.

Returns#

LinkedDataLinkResult — The link with its trail

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ReattachLinkRequest.from_json(r"""
{
  "link_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>",
  "target": {}
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).reattach_link(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

replace_linked_data#

Python#
def replace_linked_data(self, request: str, file: Optional[bytes] = None) -> ReplaceLinkedDataResult

Replace an item from a Version on. A new datasheet for a pump that was swapped in v12: one call adds the new item (item of the JSON request part, as an item of LinkData; a FILE is the file part), linked from from_version_uuid on to the objects the old item is on there, and ends the old item's links from that Version, so the older Versions keep the old one. A link the old item got on that very Version is taken off (unlinked), and when that was all of the old item, it is deleted (deleted, restorable). The new item names the one it replaces (replaces_item_uuid; GetLinkedData answers both ways). Only the links on the model of from_version_uuid are replaced. Needs write rights on the model.

OperationReplaceLinkedData · POST /openapi/linkeddata/ReplaceLinkedData
Scopelinks:write

Parameters#

NameTypeDescription
requeststrrequiredA JSON-encoded ReplaceLinkedDataSpec (item_uuid, from_version_uuid, item)
filebytesoptionalThe file. The new file, when the new item is a FILE

Returns#

ReplaceLinkedDataResult — The new item and its links, and what happened to the old one's

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = r"""
{
  "item_uuid": "00000000-0000-0000-0000-000000000000",
  "from_version_uuid": "00000000-0000-0000-0000-000000000000",
  "item": {
    "kind": "URL"
  }
}
"""
file = "drawing.pdf"

# 3. The call
result = bimworks.LinkedDataApi(client).replace_linked_data(request=request, file=file)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

restore_linked_data#

Python#
def restore_linked_data(self, restore_linked_data_request: RestoreLinkedDataRequest) -> RestoreLinkedDataResult

Bring deleted items back. Their links were kept; they show again where they were. 410 RETENTION_PASSED when an item was deleted longer ago than the retention period. Needs write rights on the item's model.

OperationRestoreLinkedData · POST /openapi/linkeddata/RestoreLinkedData
Scopelinks:write

Parameters#

NameTypeDescription
restore_linked_data_requestRestoreLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of RestoreLinkedData's request body.

Returns#

RestoreLinkedDataResult — The items restored

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.RestoreLinkedDataRequest.from_json(r"""
{
  "item_uuids": [
    "00000000-0000-0000-0000-000000000000"
  ]
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).restore_linked_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

unlink_data#

Python#
def unlink_data(self, unlink_data_request: UnlinkDataRequest) -> UnlinkDataResult

Take links off their objects, on every Version. An item that would lose its last link is deleted instead (it can be restored, back on that object). Needs write rights on each link's model; nothing is changed when one is refused.

OperationUnlinkData · POST /openapi/linkeddata/UnlinkData
Scopelinks:write

Parameters#

NameTypeDescription
unlink_data_requestUnlinkDataRequestrequiredThe request: its properties are those of the model, its JSON that of UnlinkData's request body.

Returns#

UnlinkDataResult — The links taken off, and the items deleted because they lost their last link

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.UnlinkDataRequest.from_json(r"""
{
  "link_uuids": [
    "00000000-0000-0000-0000-000000000000"
  ]
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).unlink_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

update_linked_data#

Python#
def update_linked_data(self, update_linked_data_request: UpdateLinkedDataRequest) -> LinkedDataItem

Edit the title, description, category, validity or identifier system of an item. The content never changes; a new file is a new item. Send the row_version you read; a stale one answers 409 VERSION_CONFLICT, naming who changed the item. An absent field keeps its value, an empty string clears it (the title falls back to the file name). Needs write rights on the item's model.

OperationUpdateLinkedData · POST /openapi/linkeddata/UpdateLinkedData
Scopelinks:write

Parameters#

NameTypeDescription
update_linked_data_requestUpdateLinkedDataRequestrequiredThe request: its properties are those of the model, its JSON that of UpdateLinkedData's request body.

Returns#

LinkedDataItem — The item as it is now

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.UpdateLinkedDataRequest.from_json(r"""
{
  "item_uuid": "00000000-0000-0000-0000-000000000000",
  "row_version": 0,
  "title": "",
  "description": "",
  "category": "",
  "valid_until": "",
  "identifier_system": ""
}
""")

# 3. The call
result = bimworks.LinkedDataApi(client).update_linked_data(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))