How can I add data to a repeatable component inside a collection type using a beforeCreate lifecycle function in Strapi?
05:33 14 Nov 2025

In my collection Product i have a field named "Natritional" which a repeatable field with has:
value (int)
nutrition (relation to nutritions)

i want fill the repeatble field beforeCreate with data. Every other field type is working, but i cant fill my repeatable field by array.

export default {
  async beforeCreate(event) {
    const { data } = event.params; 
    try {
      // Call external API
      const response = await axios.get(`http://127.0.0.1:8000/api/import/${data.GTIN}`);
      

      // Set a field in the new entry based on API response
      /*if (response.data.summary) {
        data.summary = response.data.summary;
      }*/

      // Optionally modify other fields
      const product = response.data.products.product;
      data.title = product.pbm_produktname_mittel;
      data.weight = product.ihf_nettofuellmenge_oder_mengenangabe;
      data.price = product.preis_empfohlener_verkaufspreis_deutschland;
      data.shortDescription = product.markinf_produktbeschreibung_kurz;
      data.description = product.markinf_produktbeschreibung_mittel;
      data.longDescription = product.markinf_produktbeschreibung_lang;
      let nut = await getNutrition(product)
      /*give back 
        [
          { nutrition: 1, value: 14 },
          { nutrition: 3, value: 30 },
          { nutrition: 8, value: 80 },
          { nutrition: 10, value: 14 }
        ]
        */
      console.log(nut)
      data.nutritional = nut;

    } catch (error) {
      strapi.log.error('❌ Failed to fetch external data:', error);
      // Optionally prevent creation
      // throw new Error('Cannot create entry, external API failed');
    }
  },
};
data.nutritional

wants an id

[2025-11-14 12:23:09.626] error: Invalid id, expected a string or integer, got [object Object]Error: Invalid id, expected a string or integer, got [object Object]

How can i fill the field by my API?

enter image description here

javascript strapi