Search code examples
autodesk-forgeautodeskautodesk-bim360

BAD_INPUT for update version API in Autodek Forge


I'm trying to upload file to BIM360DOCS. Referring this I could successfully upload the first version of file, but I'm facing issues while updating the version. For updating version of file, I created a storage location, uploaded a file to the storage location, But I try to update the version, I'm getting 400 in response.

I'm referring this method.

const body: CreateVersion = {
    jsonapi: { version: "1.0" },
    data: {
        type: "versions",
        attributes: {
            name: fileName,
            extension: {
                type: versions:autodesk.bim360:File" // "versions:autodesk.core:File",
                version: "1.0",
                schema: {
                    href: ""
                }
            }
        },
        relationships: {
            item: {
                data: {
                    type: "items",
                    id: folderId
                }
            },
            storage: {
                data: {
                    type: "objects",
                    id: objectId
                }
            }
        }
    }
}

const version = await new VersionsApi().postVersion(projectId, body, internalTokenClient, internalToken)

But this gives me 400 ERROR saying

errors: [
{
  id: '92######-####-####-####-######c98bb5',
  status: '400',
  code: 'BAD_INPUT',
  title: 'One or more input values in the request were bad',
  detail: 'The object is not the correct type.'
}

]

Whereas I'm passing 'projectId', 'internalTokenClient', 'internalToken' correctly, as same for creating first version of file. Is there any issue in my payload?

I've also tried it in postman, gives same error. I've added postman screenshot for referenceenter image description here.


Solution

  • I was passing "folderId" in relationships instead of relationship lineage. Tried passing lineage from previous version response worked properly.

    const body: CreateVersion = {
         jsonapi: { version: "1.0" },
         data: {
             type: "versions",
             attributes: {
                 name: fileName,
                 extension: {
                    type: versions:autodesk.bim360:File"
                    version: "1.0",
                    schema: {
                        href: ""
                    }
                 }
            },
            relationships: {
                item: {
                    data: {
                        type: "items",
                        id: <relationship lineage from previous version>
                    }
                },
                storage: {
                    data: {
                        type: "objects",
                        id: objectId
                    }
                }
            }
        }
    }
    
    
    const version = await new VersionsApi().postVersion(projectId, body, internalTokenClient, internalToken)