使用 Autodesk 创建文件版本 API

Create File Version with Autodesk API

从文档中的 question, I am getting stuck at Step 5 开始。我收到 400 错误,提示我发送的某些数据不正确,但我认为我已完全匹配代码。

def create_version_for_file(self, file_name, project_id, folder_id, object_id):
    url = '{}data/v1/projects/{}/items'.format(self.DOMAIN, project_id)
    logger.info('Starting version create at %s for file_name %s, folder %s, object %s',
                url, file_name, folder_id, object_id)
    data = {
        "jsonapi": {"version": "1.0"},
        "data": {
            "type": "items",
            "attributes": {
                "displayName": file_name,
                "extension": {
                    "type": "items:autodesk.core:File",
                    "version": "1.0"
                }
            },
            "relationships": {
                "tip": {
                    "data": {
                        "type": "versions",
                        "id": "1"
                    }
                },
                "parent": {
                    "data": {
                        "type": "folders",
                        "id": folder_id
                    }
                }
            }
        },
        "included": [
            {
                "type": "versions",
                "id": "1",
                "attributes": {
                    "name": file_name,
                    "extension": {
                        "type": "versions:autodesk.core:File",
                        "version": "1.0"
                    }
                },
                "relationships": {
                    "storage": {
                        "data": {
                            "type": "objects",
                            "id": object_id
                        }
                    }
                }
            }
        ]
    }
    response = self.session.post(url, json=data, headers={
        'content-type': 'application/vnd.api+json',
        'accept': 'application/vnd.api+json'
    })
    if response.status_code != status.HTTP_201_CREATED:
        logger.warn('Version create for %s failed with status %s: %s', file_name, response.status_code,
                    response.content)
        return None
    return json.loads(response.content)

但是,请求总是失败,像这样:

Upload succeeded for README.md 2017-10-12 16:53:15,943 
Starting version create at https://developer.api.autodesk.com/data/v1/projects/b.f19577f2-c4da-428f-9625-bb53bf434cca/items for file_name README.md, folder urn:adsk.wipprod:fs.folder:co.Hx1ePxPtS1e0P-Ib9qudyQ, object urn:adsk.objects:os.object:3a06e38e-4cac-4ffc-981f-0e5c4e4078aab.f19577f2-c4da-428f-9625-bb53bf434cca/d14c3591-d339-4e62-907c-6f0c8b58b743.md
Version create for README.md failed with status 400: {"jsonapi":{"version":"1.0"},"errors":[{"id":"bfbf0a93-c92a-47af-9ce7-a6af48594e44","status":"400","code":"BAD_INPUT","title":"One or more input values in the request were bad","detail":"Request input is invalid for this operation."}]}

所有变量的示例值都在上面日志的右侧。

由此forum response, the tutorial is out-of-date and you should use autodesk.bim360:File (but not autodedsk.bim360:File as the typo suggests) in place of autodesk.core:File. There is a more recent example here..

它仍然无法正常工作,但至少我的错误转移到了 The urn must be an unassigned urn prepared by the create storage endpoint, by the same user.

这可能设置正确,但您可能在错误的文件夹中创建了存储位置。从我在论坛 post 中建议的教程中,您需要向下导航一级以避免在 BIM 360 Docs 的根文件夹中创建存储位置。尝试返回您的步骤并按照教程中的建议进行操作。关注第 4 步

  1. 授权网络流程(这将为我们提供获取 oauth 令牌所需的代码)

  2. 对身份验证的其余调用 API 以获取 3 条腿令牌 GET 调用以获取我们在 BIM 360 文档中可以访问哪些集线器的详细信息(BIM 360 需要注册 APP API访问)

  3. GET 调用以查找具有您的资源的项目

  4. GET 调用以查找将进行上传的文件夹(计划、项目文件、绘图)。

    4.1 额外的步骤可以包括访问子文件夹。

  5. POST调用在之前定义的文件夹中创建存储位置

  6. PUT调用上传文件到存储位置

  7. POST调用创建上传文件的第一个版本。

检查 BIM 360 Docs 以查看您最近上传的文件。