使用BIM360 API创建问题时,可以使用自定义属性映射来指定问题类型。以下是使用Python和BIM360 API创建问题的示例代码:
import requests
import json
# BIM360 API的基本URL
base_url = "https://developer.api.autodesk.com"
# 认证信息
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
access_token = "YOUR_ACCESS_TOKEN"
# 创建问题的URL
create_issue_url = base_url + "/issues/v1/containers/:container_id/issues"
# 自定义属性映射
custom_attributes_mapping = {
"问题类型": "type",
"严重程度": "severity",
"优先级": "priority"
}
# 创建自定义属性映射的函数
def create_custom_attributes_mapping(container_id):
url = base_url + "/issues/v1/containers/:container_id/attributes/mappings"
headers = {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/vnd.api+json"
}
data = {
"data": {
"type": "attribute-mapping",
"attributes": {
"custom-attributes-mapping": custom_attributes_mapping
}
}
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
mapping_id = response.json()["data"]["id"]
return mapping_id
# 创建问题的函数
def create_issue(container_id, mapping_id, attributes):
url = create_issue_url.replace(":container_id", container_id)
headers = {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/vnd.api+json"
}
data = {
"data": {
"type": "issue",
"attributes": attributes,
"relationships": {
"custom-attributes-mapping": {
"data": {
"type": "attribute-mapping",
"id": mapping_id
}
}
}
}
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
issue_id = response.json()["data"]["id"]
return issue_id
# 示例用法
container_id = "YOUR_CONTAINER_ID"
mapping_id = create_custom_attributes_mapping(container_id)
attributes = {
"title": "Problem with the door",
"description": "The door is not closing properly",
"type": "Door",
"severity": "High",
"priority": "Urgent"
}
issue_id = create_issue(container_id, mapping_id, attributes)
print("Created issue with ID:", issue_id)
请确保替换示例代码中的以下内容:
YOUR_CLIENT_ID
:您的BIM360 API客户端ID。YOUR_CLIENT_SECRET
:您的BIM360 API客户端密钥。YOUR_ACCESS_TOKEN
:您的BIM360 API访问令牌。YOUR_CONTAINER_ID
:您的BIM360项目容器ID。此示例代码使用Python的requests
库来发送HTTP请求。在运行代码之前,请确保已安装requests
库。您可以使用以下命令安装它:
pip install requests
这个示例代码将创建一个自定义属性映射,然后使用该映射创建一个问题。您可以根据自己的需求修改自定义属性映射和问题属性。
上一篇:Bim360 API的位置
下一篇:BIM360 Docs传输协议