> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Relate assets


Cloudinary's related assets functionality allows users to establish relationships between assets based on specific organizational needs and criteria. By manually configuring these associations, users can create meaningful connections between assets within their library, making it easier for other users to discover and locate similar or associated assets.

You can relate any of the assets in your product environment to each other to create groupings or bundles. Here are some use cases where you might need to use related assets: 

* Relate videos and images of the same product.
* Relate a video with its peripheral assets (transcript, poster, etc).
* Relate an image with other images created using that image.
* Relate images of a product with companion assets (e.g. manual, warranty, etc).
* Relate similar product shots but from different angles or for different purposes.
* Relate logo images and other marketing assets with a 'Brand Guidelines' PDF.
* Relate an image with other assets that use it as an overlay.

## Add related assets

The [add_related_assets](admin_api#add_related_assets) method allows you to indicate that a specified asset is logically related to other assets in some way. This is a bidirectional process, meaning that the asset will also be added as a related\_asset to all the other assets specified. The relation is also a one to many relationship, where the asset is related to all the assets specified, but those assets are not also related to each other.

The `add_related_assets` method accepts the following parameters:

* `public_id` or `asset_id` - Either the public ID of the asset, or its asset ID.
* `assets_to_relate` - Relates the asset to all the other assets specified in this array of up to 10 assets, specified by either `resource_type/type/public_id` or by `asset_id`. **For example**: `["image/upload/dog","video/authenticated/cat"]` or `["e12345b0efc00c0fcf","f12345a5c7c00c0f12"]`

### Examples

1. Relate the image with a public ID of 'dog' to the assets with public IDs of 'image/authenticated/dog_license' and 'raw/upload/dog_subtitles.srt':

    ```multi
    |curl
    curl \
     -d '{"assets_to_relate":["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"]}' \
     -X POST \
     https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/related_assets/image/upload/dog

    |ruby
    result = Cloudinary::Api.add_related_assets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])

    |php_2
    $result = $api->addRelatedAssets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"]);


    |python
    result = cloudinary.api.add_related_assets("dog", 
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])

    |nodejs
    cloudinary.v2.api.add_related_assets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])
      .then(result=>console.log(result)); 

    |java
    cloudinary.api().addRelatedResources("dog", 
      Arrays.asList(
        "raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"),
      ObjectUtils.emptyMap());

    |csharp
    var assetIds = new List<string>(){"raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"};
    cloudinary.AddRelatedResources(new AddRelatedResourcesParams(){
      PublicId = "dog",
      AssetsToRelate = assetIds
    });

    |go
    resp, err := cld.Admin.AddRelatedAssets(ctx, admin.AddRelatedAssetsParams{
      PublicID:  "dog",
   	 AssetsToRelate: []string{"raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"}})

    |cli
    cld admin add_related_assets dog raw/upload/dog_subtitles.srt,image/authenticated/dog_license
    ```

2. Relate the asset with an asset ID of 'c789c1234bbb0e' to the assets with IDs of 'f12345a5c789c' and 'bbb0efc00c0f12':

    ```multi
    |curl
    curl \
     -d '{"assets_to_relate":["f12345a5c789c","bbb0efc00c0f12"]}' \
     -X POST \
     https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/related_assets/c789c1234bbb0e
    
    |ruby
    result = Cloudinary::Api.add_related_assets_by_asset_id("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"])
    
    |php_2
    $result = $api->addRelatedAssetsByAssetId("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"]);
    
    
    |python
    result = cloudinary.api.add_related_assets_by_asset_id("c789c1234bbb0e", 
      ["f12345a5c789c","bbb0efc00c0f12"])
    
    |nodejs
    cloudinary.v2.api.add_related_assets_by_asset_id("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"])
      .then(result=>console.log(result)); 
    
    |java
    cloudinary.api().addRelatedResourcesByAssetId("c789c1234bbb0e", 
      Arrays.asList(
        "f12345a5c789c","bbb0efc00c0f12"),
      ObjectUtils.emptyMap());
    
    |csharp
    var assetIds = new List<string>(){"f12345a5c789c","bbb0efc00c0f12"};
    cloudinary.AddRelatedResourcesByAssetId(new AddRelatedResourcesByAssetIdParams(){
      AssetId = "c789c1234bbb0e",
      AssetsToRelate = assetIds
    });
    
    |go
    resp, err := cld.Admin.AddRelatedAssetsByAssetId(ctx, admin.AddRelatedAssetsByAssetIdParams{
      AssetId:        "c789c1234bbb0e",
    	AssetsToRelate: []string{"f12345a5c789c","bbb0efc00c0f12"}})
    
    |cli
    cld admin add_related_assets_by_asset_id c789c1234bbb0e f12345a5c789c bbb0efc00c0f12
    ```

## Delete related assets

The [delete_related_assets](admin_api#delete_related_assets) method allows you to unrelate an asset from other assets. This is a bidirectional process, meaning that the asset will also be removed as a related\_asset from all the other assets specified. 

The `delete_related_assets` method accepts the following parameters:

* `public_id` or `asset_id` - Either the public ID of the asset, or its asset ID.
* `assets_to_unrelate` - Unrelates the asset from all the other assets specified in this array of assets, specified by either `resource_type/type/public_id` or by `asset_id`. **For example**: `["image/upload/dog","video/authenticated/cat"]` or `["e12345b0efc00c0fcf","f12345a5c7c00c0f12"]`

### Examples

1. Unrelate the asset with a public ID of 'dog' from the assets with public IDs of 'raw/upload/dog_subtitles.srt' and 'video/authenticated/animals':

    ```multi
    |curl
    curl \
     -d '{"assets_to_unrelate":["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"]}' \
     -X POST \
     https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/related_assets/image/upload/dog
    
    |ruby
    result = Cloudinary::Api.delete_related_assets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])
    
    |php_2
    $result = $api->deleteRelatedAssets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"]);
    
    
    |python
    result = cloudinary.api.delete_related_assets("dog", 
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])
    
    |nodejs
    cloudinary.v2.api.delete_related_assets("dog",
      ["raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"])
      .then(result=>console.log(result)); 
    
    |java
    cloudinary.api().deleteRelatedResources("dog", 
      Arrays.asList(
        "raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"),
      ObjectUtils.emptyMap());
    
    |csharp
    var assetIds = new List<string>(){"raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"};
    cloudinary.DeleteRelatedResources(new DeleteRelatedResourcesParams(){
      PublicId = "dog",
      AssetsToRelate = assetIds
    });
    
    |go
    resp, err := cld.Admin.DeleteRelatedAssets(ctx, admin.DeleteRelatedAssetsParams{
      PublicID:  "dog",
    	AssetsToRelate: []string{"raw/upload/dog_subtitles.srt", "image/authenticated/dog_license"}})
    
    |cli
    cld admin delete_related_assets dog raw/upload/dog_subtitles.srt,image/authenticated/dog_license
    ```

2. Unrelate the asset with a asset ID of 'c789c1234bbb0e' from the assets with IDs of 'a5c789c5c745a' and 'a1623c3b234a':
    
    ```multi
    |curl
    curl \
     -d '{"assets_to_unrelate":["f12345a5c789c","bbb0efc00c0f12"]}' \
     -X POST \
     https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/related_assets/c789c1234bbb0e
    
    |ruby
    result = Cloudinary::Api.delete_related_assets_by_asset_id("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"])
    
    |php_2
    $result = $api->deleteRelatedAssetsByAssetId("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"]);
    
    
    |python
    result = cloudinary.api.delete_related_assets_by_asset_id("c789c1234bbb0e", 
      ["f12345a5c789c","bbb0efc00c0f12"])
    
    |nodejs
    cloudinary.v2.api.delete_related_assets_by_asset_id("c789c1234bbb0e",
      ["f12345a5c789c","bbb0efc00c0f12"])
      .then(result=>console.log(result)); 
    
    |java
    cloudinary.api().deleteRelatedResourcesByAssetId("c789c1234bbb0e", 
      Arrays.asList(
        "f12345a5c789c","bbb0efc00c0f12"),
      ObjectUtils.emptyMap());
    
    |csharp
    var assetIds = new List<string>(){"f12345a5c789c","bbb0efc00c0f12"};
    cloudinary.DeleteRelatedResourcesByAssetId(new DeleteRelatedResourcesByAssetIdParams(){
      AssetId = "c789c1234bbb0e",
      AssetsToUnrelate = assetIds
    });
    
    |go
    resp, err := cld.Admin.DeleteRelatedAssetsByAssetId(ctx, admin.DeleteRelatedAssetsByAssetIdParams{
      AssetId:  "c789c1234bbb0e",
    	AssetsToUnrelate: []string{"f12345a5c789c","bbb0efc00c0f12"}})
    
    |cli
    cld admin delete_related_assets_by_asset_id c789c1234bbb0e f12345a5c789c bbb0efc00c0f12
    ```

## List related assets

The list of related assets is stored with the asset and is returned in the response when calling the [Get details of a single resource](admin_api#get_details_of_a_single_resource_by_public_id) method with the `related` parameter set to `true`.

For example, to get the details of an image with the public ID of 'red_shoe' and include the list of related assets:

```multi
|curl
curl https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/raw/upload/red_shoe

|ruby
result = Cloudinary::Api
.resource('red_shoe',
  related: true)

|php_2
$result = $api
->asset("red_shoe",
  ["related" => true]);

|python
result = cloudinary.api\
.resource("red_shoe",
  related = True)

|nodejs
cloudinary.v2.api
.resource('red_shoe', 
  { related: true})
.then(result=>console.log(result)); 

|java
result = api.resource("red_shoe",
  ObjectUtils.asMap("related", true));

|csharp
var getResource = new GetResourceParams("red_shoe"){
Related = true };
var info = cloudinary.GetResource(getResource);

|go
resp, err := cld.Admin.Asset(ctx, admin.AssetParams{
        PublicID:   "red_shoe",
        Related:    api.Bool(true)})

|cli
cld admin resource red_shoe related=true
```

