Create Relationships
This tutorial demonstrates how to create a relationship between two entities (for example, an asset and a document). The steps include verifying compatibility of entity types in the Relationships service, finding information about the entities you want to create a relationship for, and creating the relationship between the entities. For information about the Relationships API, see the Field Guide.
Note that in order to create a relationship between two entities, the entities must already exist, and the caller must have permission to access both entities in the proposed relationship.
Before You Begin
- Register an app, and select the Data Management and BIM 360 APIs.
- Acquire a 3-legged OAuth token with
data:createdata:readanddata:writescopes. - Verify that you have access to the relevant hub, project, folder and contents.
- Find the relationships container ID for the relevant project.
Note that this tutorial assumes you are familiar with the BIM 360 Assets and Document Management APIs.
Step 1: Verify Entity Compatibility
You first need to check whether the entities you want to associate with each other are compatible.
To verify compatibility, call GET utility/relationships:writable, and find the object containing the relationship domain and entity type you want to create a relationship against. For example, check whether you can create a relationship between an asset and a document. The asset domain is autodesk-bim360-asset, and the entity type is asset. In this example, the allow attribute contains an array of entity types that assets can have a relationship with. For a list of domains and their entity types, see the Relationship Querying tutorial.
Note that some domains have a bim360 prefix, and others have a construction prefix.
Request
Response (200)
Step 2: Find Information About Entities
You need to find information about the entities you want to create a relationship for. For example, to create a relationship between an asset and a document, you need to call GET assets to find the ID of the asset, and GET folders/:folder_id/contents to find the ID of the document.
Step 3: Create a Relationship
To create relationships between compatible entities, use the information you found in the previous steps and the container ID to call PUT containers/:containerId/relationships. Note that one entity may be related to a batch of up to 20 entities within a single API call.
In this example, we are creating a relationship between an asset and a document.
Example Request
Example Response
Note that you can create relationships by supplying your own relationship IDs (UUID). For example, you can choose to use b544a7eb-3c64-4a56-a7ff-392d0441015f as the ID. If the ID is already in use, the server will reject the request with an HTTP 409 Conflict error.
Example Request
Example Conflict Response
Imported from the Autodesk Platform Services documentation: https://aps.autodesk.com/en/docs/acc/v1/tutorials/relationships/relationships-create.