<p>Okay I found a way to do it if it can help someone: </p>

<pre><code>$description_fr = ($entry-&gt;summary) ? $entry-&gt;summary : ($entry-&gt;body) ? $entry-&gt;body : '';
$entry_en = Entry::find()-&gt;id($entry-&gt;id)-&gt;siteId(2)-&gt;one();
$description_en = ($entry_en['summary']) ? $entry_en['summary'] : ($entry_en['body']) ? $entry_en['body'] : '';
$entry_de = Entry::find()-&gt;id($entry-&gt;id)-&gt;siteId(3)-&gt;one();
$description_de = ($entry_de['summary']) ? $entry_de['summary'] : ($entry_de['body']) ? $entry_de['body'] : '';
</code></pre>

CC BY-SA 4.0
2020-01-16T15:58:26.143Z
2020-01-16T15:58:26.143Z
Elodie Grondin
<p>I'd like to get a field value in 3 differents locales in the same element-api endpoint but I can't make a request similar to this one :  craft.entries.siteId($siteId).id($entryId).one() in twig.</p>

<pre><code>&lt;?php

use Craft;
use craft\elements\Entry;

return [
  'endpoints' =&gt; [
    'exhibitions.json' =&gt; function() {
      return [
        'elementType' =&gt; Entry::class,
        'criteria' =&gt; [
          'section' =&gt; 'exhibitions',
          // 'locale' =&gt; ['francais','english', 'deutsch']
        ],
        'transformer' =&gt; function(Entry $entry) {

          // -- Description --
          $description_fr = ($entry-&gt;summary) ? $entry-&gt;summary : ($entry-&gt;body) ? $entry-&gt;body : '';
          // $entry_en = $craft-&gt;entries-&gt;siteId(2).id($entry-&gt;id).one();
          // $description_en = ($entry_en-&gt;summary) ? $entry_en-&gt;summary : ($entry_en-&gt;body) ? $entry_en-&gt;body : '';
          // $entry_de = $craft-&gt;entries-&gt;siteId(3).id($entry-&gt;id).one();
          // $description_de = ($entry_de-&gt;summary) ? $entry_de-&gt;summary : ($entry_de-&gt;body) ? $entry_de-&gt;body : '';

          // -- Tags --
          $tags = '['.$entry-&gt;exhibitionsType-&gt;label.']';
          foreach ($entry-&gt;exhibitionsCats as $key =&gt; $cat) {
            $tags .= ',['.$cat['title'].']';
          }

          return [
            'type' =&gt; [
              array('target_id' =&gt; 'event')
            ],
            'title' =&gt; [
              array('value' =&gt; $entry-&gt;title)
            ],
            'field_subtitle' =&gt; [
              array('value' =&gt; $entry-&gt;subtitle)
            ],
            'field_description_fr' =&gt; [
              array('value' =&gt; $description_fr)
            ],
            // 'field_description_en' =&gt; [
            //   array('value' =&gt; $description_en)
            // ],
            // 'field_description_de' =&gt; [
            //   array('value' =&gt; $description_de)
            // ],
            'pictures' =&gt; [
              'url' =&gt; $entry-&gt;banner-&gt;one()-&gt;url,
              'copy' =&gt; $entry-&gt;banner-&gt;one()-&gt;legend,
              'alt' =&gt; $entry-&gt;banner-&gt;one()-&gt;legend
            ],
            'field_event_type' =&gt; [
              array('value' =&gt; '3') // Long or permanent event (3)
            ],
            'field_date' =&gt; [
              array(
                'value '=&gt; $entry-&gt;fromDate-&gt;format('Y-m-dTH:i:s'),
                'end_value '=&gt; $entry-&gt;toDate-&gt;format('Y-m-dTH:i:s'),
                'rrule '=&gt; null,
              )
            ],
            'field_state' =&gt; [
              array('value' =&gt; 'scheduled')
            ],
            'field_type' =&gt; [
              array('target_id' =&gt; 6) // Audience - Pour tout public (6)
            ],
            'field_categories' =&gt; [
              array('target_id' =&gt; 24347) // Exhibitions (24347)
            ],
            'field_tags_rest' =&gt; [
              array('value' =&gt; $tags)
            ],
            'field_location' =&gt; [
              array('target_id' =&gt; 5179)
            ],
            'field_websites' =&gt; [
              array(
                'uri' =&gt; $entry-&gt;url,
                'title' =&gt; $entry-&gt;title)
            ],
            'field_email_address' =&gt; [
              array('value' =&gt; getenv('EIL_EMAIL'),)
            ],
          ];
        },
      ];
    }
  ]
];
</code></pre>

<craft3><plugin-elementapi>
How can I get field's value of entry in other site locale in my element-api endpoint?
# How can I get field's value of entry in other site locale in my element-api endpoint?

(Asked by: username_0 on 2020-01-16)

I'd like to get a field value in 3 differents locales in the same element-api endpoint but I can't make a request similar to this one :  craft.entries.siteId($siteId).id($entryId).one() in twig.
 [
    'exhibitions.json' => function() {
      return [
        'elementType' => Entry::class,
        'criteria' => [
          'section' => 'exhibitions',
          // 'locale' => ['francais','english', 'deutsch']
        ],
        'transformer' => function(Entry $entry) {

          // -- Description --
          $description_fr = ($entry->summary) ? $entry->summary : ($entry->body) ? $entry->body : '';
          // $entry_en = $craft->entries->siteId(2).id($entry->id).one();
          // $description_en = ($entry_en->summary) ? $entry_en->summary : ($entry_en->body) ? $entry_en->body : '';
          // $entry_de = $craft->entries->siteId(3).id($entry->id).one();
          // $description_de = ($entry_de->summary) ? $entry_de->summary : ($entry_de->body) ? $entry_de->body : '';

          // -- Tags --
          $tags = '['.$entry->exhibitionsType->label.']';
          foreach ($entry->exhibitionsCats as $key => $cat) {
            $tags .= ',['.$cat['title'].']';
          }

          return [
            'type' => [
              array('target_id' => 'event')
            ],
            'title' => [
              array('value' => $entry->title)
            ],
            'field_subtitle' => [
              array('value' => $entry->subtitle)
            ],
            'field_description_fr' => [
              array('value' => $description_fr)
            ],
            // 'field_description_en' => [
            //   array('value' => $description_en)
            // ],
            // 'field_description_de' => [
            //   array('value' => $description_de)
            // ],
            'pictures' => [
              'url' => $entry->banner->one()->url,
              'copy' => $entry->banner->one()->legend,
              'alt' => $entry->banner->one()->legend
            ],
            'field_event_type' => [
              array('value' => '3') // Long or permanent event (3)
            ],
            'field_date' => [
              array(
                'value '=> $entry->fromDate->format('Y-m-dTH:i:s'),
                'end_value '=> $entry->toDate->format('Y-m-dTH:i:s'),
                'rrule '=> null,
              )
            ],
            'field_state' => [
              array('value' => 'scheduled')
            ],
            'field_type' => [
              array('target_id' => 6) // Audience - Pour tout public (6)
            ],
            'field_categories' => [
              array('target_id' => 24347) // Exhibitions (24347)
            ],
            'field_tags_rest' => [
              array('value' => $tags)
            ],
            'field_location' => [
              array('target_id' => 5179)
            ],
            'field_websites' => [
              array(
                'uri' => $entry->url,
                'title' => $entry->title)
            ],
            'field_email_address' => [
              array('value' => getenv('EIL_EMAIL'),)
            ],
          ];
        },
      ];
    }
  ]
];

**Tags:** craft3, plugin-elementapi


---

## 1 answers

### Answer by username_0 on 2020-01-16. Score: 3 | Accepted answer

Okay I found a way to do it if it can help someone: 
$description_fr = ($entry->summary) ? $entry->summary : ($entry->body) ? $entry->body : '';
$entry_en = Entry::find()->id($entry->id)->siteId(2)->one();
$description_en = ($entry_en['summary']) ? $entry_en['summary'] : ($entry_en['body']) ? $entry_en['body'] : '';
$entry_de = Entry::find()->id($entry->id)->siteId(3)->one();
$description_de = ($entry_de['summary']) ? $entry_de['summary'] : ($entry_de['body']) ? $entry_de['body'] : '';


---

