Reputation: 181
The versions API endpoint mentions that it can be used to make a copy of a document. It appears that the copyFrom parameter is the http encoded value of the source file urn. What is the value of relationships.item.data.type.itemsid in the example? Do I need to first create an empty file object and then provide that Id in the request body?
Upvotes: 1
Views: 612
Reputation: 7070
The item id is the id of Data Management API the file that you want to copy from it. You can obtain it via calling:
You don't have to create an empty file object, just call the API: https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-POST/
For example,
Here is an RVT model with stored in Docs, and its item data is the below:
{
"type": "items",
"id": "urn:adsk.wipprod:dm.lineage:rH_L4XJsTmeiYA4ixCVNAA", //!<<< Item id
"attributes": {
"displayName": "rac_basic_sample_project.rvt",
"createTime": "2019-09-25T06:56:26.0000000Z",
//...
"lastModifiedTime": "2019-09-25T06:56:27.0000000Z",
//...
"hidden": false,
"reserved": false,
"extension": {
"type": "items:autodesk.bim360:File",
"version": "1.0",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/items:autodesk.bim360:File-1.0"
},
"data": {
"sourceFileName": "rac_basic_sample_project.rvt"
}
}
},
//...
}
Then call https://developer.api.autodesk.com/data/v1/projects/{PROJECT_ID}/items/urn:adsk.wipprod:dm.lineage:rH_L4XJsTmeiYA4ixCVNAA/versions to get its version records:
{
"type": "versions",
"id": "urn:adsk.wipprod:fs.file:vf.rH_L4XJsTmeiYA4ixCVNAA?version=1", //!<<< Version id
"attributes": {
"name": "rac_basic_sample_project.rvt",
"displayName": "rac_basic_sample_project.rvt",
"createTime": "2019-09-25T06:56:26.0000000Z",
//...
"lastModifiedTime": "2019-09-25T06:57:54.0000000Z",
//...
"versionNumber": 1,
"storageSize": 17813504,
"fileType": "rvt",
"extension": {
"type": "versions:autodesk.bim360:File",
"version": "1.0",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/versions:autodesk.bim360:File-1.0"
},
"data": {
"processState": "PROCESSING_COMPLETE",
"extractionState": "SUCCESS",
"splittingState": "NOT_SPLIT",
"reviewState": "NOT_IN_REVIEW",
"revisionDisplayLabel": "1",
"sourceFileName": "rac_basic_sample_project.rvt"
}
}
},
//...
}
Now you want to copy a specific version urn:adsk.wipprod:fs.file:vf.rH_L4XJsTmeiYA4ixCVNAA?version=1
of this item to another folder urn:adsk.wipprod:fs.folder:co.0xaYa2rVTJuFiz7rxLCOQQ
. So, the API call will look like the following:
Note. The URL safe form of the version id is urn%3Aadsk.wipprod%3Afs.file%3Avf.rH_L4XJsTmeiYA4ixCVNAA%3Fversion%3D1
POST https://developer.api.autodesk.com/data/v1/projects/{PROJECT_ID}/items?copyFrom=urn%3Aadsk.wipprod%3Afs.file%3Avf.rH_L4XJsTmeiYA4ixCVNAA%3Fversion%3D1
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "items",
"relationships": {
"tip":{
"data":{
"type":"versions",
"id":"1"
}
},
"parent": {
"data": {
"type": "folders",
"id": "urn:adsk.wipprod:fs.folder:co.0xaYa2rVTJuFiz7rxLCOQQ" //!<<< The folder we want to put this file
}
}
}
},
"included":[
{
"type":"versions",
"id":"1",
"attributes":{
"name":"rac_basic_sample_project.rvt" //!<<< Version name
}
}
]
}
Hope it helps!
Upvotes: 1