---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/direct/doc/dg-v4/en/live/AdImageAssociation_Set.md
  - https://yandex.com/dev/direct/doc/dg-v4/ru/live/AdImageAssociation_Set.md
  - href: en/live/AdImageAssociation_Set.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/direct/doc/dg-v4/en/llms.txt

# Set
Adds/removes an association between an image and an ad.
To remove an association (unbind an image from an ad), pass an [AdImageAssociation](#Set-AdImageAssociation) structure in which the AdImageHash parameter is omitted or is set to NULL.

Only one image can be associated with an ad: when adding a new association, the old one is removed automatically (however, points are deducted only for adding it).

## Restrictions


{% note alert %}

The method only supports text and image ads. To work with all types of ads, use the [Ads](https://yandex.com/dev/direct/doc/ref-v5/ads/ads.html) service in version 5 of the API. [More about ad types...](https://yandex.com/dev/direct/doc/dg/objects/ad.htmlad.md)

{% endnote %}


## Input data

The input data structure in JSON is shown below.

```javascript
{
   "method": "AdImageAssociation",
   "param": {
      /* AdImageAssociationRequest */
      "Action": (string),
      "AdImageAssociations": [
         {  /* AdImageAssociation */
            "AdID": (long),
            "AdImageHash": (string),
         }
         ...
      ]
   }
}
```

Parameters are described below.


#|
||
**<sup >Parameter</sup>**
|
**<sup >Description</sup>**
|
**<sup >Required</sup>**
||

||
**<sub >AdImageAssociationRequest object</sub>**
||
||
`Action`
|
Action: Set.
|
Yes
||
||
`AdImageAssociations`
|
Array of `AdImageAssociation` objects (no more than 10,000). Each object contains an association between an image and an ad.
|
Yes
||

||
**<sub >AdImageAssociation object</sub>**
||
||
`AdID`
|
The ad ID.
|
Yes
||
||
`AdImageHash`
|
Hash of the image.

If the parameter is omitted or NULL, the association between the image and ad is removed.
|
No
||
|#

## Output data


{% note alert %}

An error when adding/removing one of the associations does not cause the entire operation to be canceled, and does not affect the success of adding/removing the other associations.

{% endnote %}


The output data structure in JSON is shown below.

```javascript
{
   "data": {
      /* AdImageAssociationResponse */
      "ActionsResult": [
         {  /* AdImageAssociationActionResult */
            "AdID": (long),
            "Errors": [
               {  /* Error */
                  "FaultCode": (int),
                  "FaultString": (string),
                  "FaultDetail": (string)
               }
               ...
            ]
         }
         ...
      ],
   }
}
```

Parameters are described below.


#|
||
**<sup >Parameter</sup>**
|
**<sup >Description</sup>**
||

||
**<sub >AdImageAssociationResponse object</sub>**
||
||
`ActionsResult`
|
Array of `AdImageAssociationActionResult` objects. Each object corresponds to an item in the `AdImageAssociations` input array and contains:

- Just the ad ID, if the association was added/removed successfully.
- The `Errors` array, if an error occurred.

The items in the array are in the same order as the objects in the `AdImageAssociations` input array.
||

||
**<sub >AdImageAssociationActionResult object</sub>**
||
||
`AdID`
|
The ad ID.
||
||
`Errors`
|
Array of `Error` objects with errors that occurred while adding/removing associations.
||

||
**<sub >Error object</sub>**
||
||
`FaultCode`
|
Error code.
||
||
`FaultString`
|
Textual message about the error.
||
||
`FaultDetail`
|
Detailed description of the reason for the error.
||
|#

## Examples of input data

# Python

```python
{
   'Action': 'Set',
   'AdImageAssociations': [
      {
         # Adding associations
         'AdID': 2571700,
         'AdImageHash': 'c6da811f75221196dd5b1a8ca703344b',
      },
      {
         # Removing associations
         'AdID': 2571745
      },

   ]
}
```

# PHP

```php
array(
   'Action' => 'Set',
   'AdImageAssociations' => array(
      array(
         # Adding associations
         'AdID' => 2571700,
         'AdImageHash' ='c6da811f75221196dd5b1a8ca703344b'
      ),
      array(
         # Removing associations
         'AdID' =2571745
      )
   )
)>
```

# Perl

```perl
{
   'Action' => 'Set',
   'AdImageAssociations' => [
      {
         # Adding associations
         'AdID' => 2571700,
         'AdImageHash' ='c6da811f75221196dd5b1a8ca703344b'
      },
      {
         # Removing associations
         'AdID' =2571745
      }
   ]
}>
```


