# coverId wird beim anlegen des Produktes per REST-API nur parziell umgesetzt

**URL:** <https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141>\
**Category:** Programmierung\
**Created:** [5. Juli 2020 um 20:57 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141 "2020-07-05T20:57:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![achilleju](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@achilleju](https://forum.shopware.com/u/achilleju)\
**Post date:** [5. Juli 2020 um 20:57 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/1 "2020-07-05T20:57:27Z")

</div>

```
 hallo, per rest-api wird das produkt korrekt angelegt, die coverId wird nur parziell umgesetzt. payload (auszug): { "id": "bdff2530a7fb49519378c5f06f321682", "coverId": "727d8eefa41c44e190021730893f2ec2", "media": [{ "id": "bdff2530a7fb49519378c5f06f321682", "mediaId": "727d8eefa41c44e190021730893f2ec2", "position": 1 }] }

```

&nbsp;

im admin-bereich wird das bild korrekt angezeigt und&nbsp;als “Cover” gekennzeichnet, wurde aber dem Cover nicht zugewiesen:

![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/d89b6ca74b411350e1ef901f03f12e78e0dd4c38.png)

im frontend wird das bild im listing nicht angezeigt, auf der detailseite erscheint das bild korrekt.

&nbsp;

---

<div class="post-metadata">

**Author:** ![achilleju](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@achilleju](https://forum.shopware.com/u/achilleju)\
**Post date:** [9. Juli 2020 um 15:53 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/2 "2020-07-09T15:53:27Z")

</div>

aufgrund eines bestehenden fehlers in der doku von shopware 6, wird das bild nicht richtig zugewiesen:

payload (auszug):  
{  
&nbsp; &nbsp; „id“: „bdff2530a7fb49519378c5f06f321682“,  
&nbsp; &nbsp; „coverId“: „cdfb2479a7fb49519378c5f06f321682“,  
&nbsp; &nbsp; „media“: [  
&nbsp; &nbsp; &nbsp; &nbsp; {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; „id“: „cdfb2479a7fb49519378c5f06f321682“,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; „mediaId“: „727d8eefa41c44e190021730893f2ec2“,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; „position“: 1  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; ]  
}

die mediaId ist die falsche - die id des dem produkt zugeordneten bildes muss hier verwendet werden.

---

<div class="post-metadata">

**Author:** ![julian.schafferhans](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@julian.schafferhans](https://forum.shopware.com/u/julian.schafferhans)\
**Post date:** [25. Mai 2022 um 12:24 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/3 "2022-05-25T12:24:06Z")

</div>

Ich denke, ich bin gerade an dem gleichen Problem. Und folgendes habe ich dazu herausgefunden:

- Es gibt Medias
- Es gibt Products
- Diese haben offenbar eine n:m-Beziehung zueinander
- → Es gibt also eine Zwischentabelle und demnach ein Zwischenobjekt Product\_Media
- Die coverId bei Product ist keine Media-ID, sondern eine Product\_Media-ID
- Man muss also ein Product\_Media-Objekt erstellen, um die Media mit Products zu verknüpfen
- Dieses Product\_Media-Objekt hat 3 Pflichtfelder: productId, mediaId, createdAt
- Wurde dieses Zwischenobjekt erstellt, kann man dessen product\_mediaId in dem Product bei coverId hinterlegen

Ich hoffe meine Erkenntnisse können bei diesem Problem weiterhelfen.

---

<div class="post-metadata">

**Author:** ![pka](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@pka](https://forum.shopware.com/u/pka)\
**Post date:** [21. September 2023 um 10:00 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/4 "2023-09-21T10:00:16Z")

</div>

Hallo zusammen.

Ich schlage mich auch gerade mit dem Upload von Produktmedien herum. Das Bild wird hochgeladen und auch im Produkt als Bild angezeigt.

Wie bekomme ich das Coverbild nun gesetzt? Ich werde aus der Doku an dieser Stelle nicht schlau.

Vorgehensweise:

1. Erstellung einer neuen Media-Resource auf /api/media (um eine MediaID zu erhalten)
2. Upload der Bilddatei auf /api/\_action/media/#MediaId#/upload…
3. Erstellung Produkt-Media auf /api/product-media mit Body:

{  
„productId“: „#ProductId#“,  
„mediaId“: „#MediaId#“  
}

Was muss ich nun tun, um auch das Coverbild zu setzen? Geht das in einem Rutsch in meinem 3. Schritt oder muss ich das hinterher irgendwie machen?

Ich würde mich sehr über einen Tipp und/oder einen Codeschnipsel freuen.  
Danke sehr.

LG  
Philip

---

<div class="post-metadata">

**Author:** ![pcs](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@pcs](https://forum.shopware.com/u/pcs)\
**Post date:** [30. September 2023 um 20:09 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/5 "2023-09-30T20:09:33Z")

</div>

Ich hab dazu gerade ein lösung gefunden…

> mediaID erstellen

```auto
/api/media?_response=basic' , [

             'body' => '{
                "mediaFolderId": "25dbd0da24504e27a60cc45be4eebc8f",
                "title": "'.$catid[brand_name].' '.$catid[products_name].' ",
                "alt": "'.$catid[brand_name].' '.$catid[products_name].' "

               }',
             'headers' => [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' => 'application/json'
              ]

            ]

dann file hoch laden

/api/_action/media/'.$mediaID.'/upload?extension='.$file_type.'&fileName='.$catid[products_image].'&_response=basic' ,
             [
             'body' => ' {"url":"'.$img.'"} '
             ,
             'headers' => [
                'Accept' => ' application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' =>'application/json'

              ]
            ]

```

dann Image und Produkt nach wahl vernknpüfen.

```auto
/api/product-media?_response=detail' , [

             'body' => '{
                    "productId": "'.$catid[products_uuid].'",
                    "mediaId": "'.$mediaID.'",
                    "position": 0

                    }',
             'headers' => [
                'Accept' => ' application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' => 'application/json'
              ],

          ]

```

Da bekommt na dann eine neue ID … die id dann an die coverID senden…

```auto
/api/product/'.$catid[products_uuid].'?_response=basic' , [
            'body' => '{
                   "coverId" : "'.$products_media_id.'"
              }
              ',
            'headers' => [
                'Accept' => ' application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' => 'application/json'
              ],

            ]

```

thats it… geht bestimmt noch komplizierter… für dich nach Welt!

---

<div class="post-metadata">

**Author:** ![Nico2](https://avatars.discourse-cdn.com/v4/letter/n/838e76/32.png) [@Nico2](https://forum.shopware.com/u/Nico2)\
**Post date:** [15. Juli 2024 um 13:47 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/6 "2024-07-15T13:47:21Z")

</div>

Danke! Ist aber wirklich extra kompliziert. Wenn man da einige tausend Artikel anlegt, dauert das ja ewig und drei Tage, wenn man alle für die Bilder 3 API Calls machen muss

---

<div class="post-metadata">

**Author:** ![pcs](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@pcs](https://forum.shopware.com/u/pcs)\
**Post date:** [23. Juli 2024 um 15:06 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/7 "2024-07-23T15:06:31Z")

</div>

geht eigentlich ganz fix…

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [4. August 2024 um 06:37 UTC](https://forum.shopware.com/t/coverid-wird-beim-anlegen-des-produktes-per-rest-api-nur-parziell-umgesetzt/68141/8 "2024-08-04T06:37:20Z")

</div>

man kann die header-Antwort von @pcs auch umgehen und seine eigene id mitschicken  
Also statt:

```auto
/api/product-media?_response=detail' , [

             'body' => '{
                    "productId": "'.$catid[products_uuid].'",
                    "mediaId": "'.$mediaID.'",
                    "position": 0

                    }',
             'headers' => [
                'Accept' => ' application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' => 'application/json'
              ],

          ]

```

macht man:

```auto
/api/product-media?_response=detail' , [

             'body' => '{
                    "id :" md5(loremipsum),
                    "productId": "'.$catid[products_uuid].'",
                    "mediaId": "'.$mediaID.'",
                    "position": 0

                    }',
             'headers' => [
                'Accept' => ' application/json',
                'Authorization' => 'Bearer '.$shopwareConnector[token]->access_token,
                'Content-Type' => 'application/json'
              ],

          ]

```
