# Manipulating the avatar via automation script?

**URL:** <https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918>\
**Category:** API & Programming\
**Created:** [February 3, 2023, 3:57pm UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918 "2023-02-03T15:57:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandi](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sandi](https://community.fibery.io/u/Sandi)\
**Post date:** [February 3, 2023, 3:57pm UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918/1 "2023-02-03T15:57:29Z")

</div>

Hi there. I’m trying to generate avatars for my TODO items in fibery using an image generator AI, but I can’t seem to access the Avatar field in an automation script.

When I `console.log(entity['Avatar']);` in the script, it prints `undefined` even though that specific entity has an avatar (that I uploaded manually). If I try to fetch the field via the API with `const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['Avatar']);`, then triggering the automation displays a “script failed” popup.

Printing out all the keys with `console.log(Object.keys(entity));` shows a list of keys without `'Avatar'`.

Is this not supported for now? Doesn’t seem like a stretch to support it since a `'Files'` field can be manipulated in a script.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [February 11, 2023, 10:44am UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918/2 "2023-02-11T10:44:30Z")

</div>

Hi @Sandi  
For historical reasons Avatar is only label shown on UI, however it is implemented as files collection with name ‘avatar/avatars’.

You can access it via

```auto
const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['avatars']);

    console.log(entityWithExtraFields);
}
```

---

<div class="post-metadata">

**Author:** ![Sandi](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sandi](https://community.fibery.io/u/Sandi)\
**Post date:** [February 11, 2023, 4:50pm UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918/3 "2023-02-11T16:50:31Z")

</div>

Haven’t tried this yet, but thanks!

---

<div class="post-metadata">

**Author:** ![gomocoop](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/gomocoop/32/6349_2.png) [@gomocoop](https://community.fibery.io/u/gomocoop)\
**Post date:** [November 26, 2024, 5:37pm UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918/4 "2024-11-26T17:37:11Z")

</div>

Is it possible to create a script that would copy the avatar from one entity to another one that has the same name?

(Quite newbie in programming here…)

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [November 27, 2024, 12:52pm UTC](https://community.fibery.io/t/manipulating-the-avatar-via-automation-script/3918/5 "2024-11-27T12:52:16Z")

</div>

It is possible, but not a simple thing to do.

Given that you have a ‘source’ entity (with the avatar you want to copy) and a ‘destination’ entity (where you want to add the avatar), your automation needs to know which these two entities are.

If you have an automation running in the source, there needs to be a way for you to tell it the destination, or vice versa.

Assuming you can identify them, your script would look something like this:

```auto
// automation running in the destination
const fibery = context.getService('fibery');
const https = context.getService('http');

// some code to get the file secret of the avatar in the source
// ...
//

// this function uploads another copy of the avatar file (using the file secret from the source)
const response = await https.postAsync('https://WORKSPACE_NAME.fibery.io/api/files/from-url', {
    'headers': {
        'Authorization': 'Token YOUR_API_TOKEN',
    },
    'body': {
         "url": "https://WORKSPACE_NAME.fibery/io/api/files/FILE_SECRET",
         method: "GET",
         name: "img.jpg",
         headers: {
           'Authorization': 'Token YOUR_API_TOKEN',
         }
    } 
});

// add the uploaded file id to the avatar collection for this entity
await fibery.addCollectionItem(entity.type, entity.id, 'avatars', response['fibery/id'])

```
