http://yourserver.com/services/createRelation ?relationType=<relation type> &target1Id=<asset id> &target2Id=<another asset id>
What does it do?
This call creates a relation of a certain type between two assets in Assets Server. For example, to add an asset to a collection.
Note: When a relation between two assets exists — even of a different type — it is not possible to create a new one.
Log in requirement
Before being able to request information from Assets Server by using a GET request or make changes to the system through a POST request, a log in to Assets Server is required. For information about the available APIs for logging in, see Assets Server REST API - introduction.
POST requests only
This REST API only accepts POST requests, not GET requests. Also, the POST request needs to include a cross-site request forgery (csrf) token.
The csrf token is a unique code which, by including it in the request, also makes the POST request unique and therefore much more secure.
The csrf token is obtained by first logging in to Assets Server through a POST request. The response that is received will include the csrf token which can then be used in subsequent POST requests as a http header:
For more information including examples, see Assets Server REST API - Performing a POST request with a csrf token.
The type of relation to create.
The id of the asset on one side of the relation.
If the relation type is a directional relation, this must be the id of the 'parent'-side.
The id of the asset on the other side of the relation.
If the relation type is a directional relation, this must be the id of the 'child'-side.
The operation returns an empty 200 OK status.
If the operation fails, an error page with a 500 error status will be returned.
http://demo.assets-server.com/services/createRelation ?relationType=contains &target1Id=ATT8CDno4QCB59QHmjwnfS &target2Id=Cbg9-_ukKEZARORmuaCsn3
Creates a relation between 2 assets. In this case between:
- People.collection (ATT8CDno4QCB59QHmjwnfS)
- Kiting.jpg (Cbg9-_ukKEZARORmuaCsn3)
You can also use the 'reverse' relation type, but then you also have to reverse the IDs used in target 1 and target 2:
http://demo.assets-server.com/services/createRelation ?relationType=contained-by &target1Id=Cbg9-_ukKEZARORmuaCsn3 &target2Id=ATT8CDno4QCB59QHmjwnfS