# API Produkt mit coverId anlegen

**URL:** <https://forum.shopware.com/t/api-produkt-mit-coverid-anlegen/104003>\
**Category:** Shopware 6 (German)\
**Created:** [10. Mai 2024 um 13:56 UTC](https://forum.shopware.com/t/api-produkt-mit-coverid-anlegen/104003 "2024-05-10T13:56:30Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [10. Mai 2024 um 13:56 UTC](https://forum.shopware.com/t/api-produkt-mit-coverid-anlegen/104003/1 "2024-05-10T13:56:30Z")

</div>

Ich habe Bilder mit der API hochgeladen (/media)  
Nun habe ich Produkte mit der API angelegt mit „coverId“ und die id des vorher hochgeladenen Bildes genutzt.  
Das Bild wandert sozusagen nicht automatisch in (/product-media) und ist dem Produkt auch nicht zugewiesen. Was mache ich hier falsch?

```auto
{
    "name": "tessdft",
    "productNumber": "ranssfgddfdfdo1m",
    "stock": 10,
    "coverId": "f4c12eae2cfe488580fefb8226b115fe",
    "taxId": "018d131737217262b7f66a47eadcbfd6",
    "price": [
        {
            "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
            "net": 1.1344537815126101,
            "gross": 1.35,
            "linked": true,
            "listPrice": null,
            "extensions": []
        }
    ]    
}

```

Danke und Gruss.

---

<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:** [10. Mai 2024 um 18:16 UTC](https://forum.shopware.com/t/api-produkt-mit-coverid-anlegen/104003/2 "2024-05-10T18:16:59Z")

</div>

Ok, scheinbar geht es nicht so.

Als erstes legt man das Produkt ohne coverId an um eine Product-Id zu bekommen.  
POST api/product

```auto
{
    "name": "tessdft",
    "productNumber": "ranssfgddfdfdo1m",
    "stock": 10,
    "taxId": "018d131737217262b7f66a47eadcbfd6",
    "price": [
        {
            "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
            "net": 1.1344537815126101,
            "gross": 1.35,
            "linked": true,
            "listPrice": null,
            "extensions": []
        }
    ]    
}

```

Dann muss man in der API /product-media ein MediaObject mit der id des Bildes und der Produkt-id erstellen.

POST api/product-media

```auto
{
    "productId": "018f6345063d703a961149792ea63850",
    "mediaId": "f4c12eae2cfe488580fefb8226b115fe", //id des Bildes
    "position": 0
}

```

Den Rückgabewert im Header nehmen und  
anschliessend in der Produkt-API /product/123465 mit PATCH die coverId übergeben

PATCH api/product/018f6345063d703a961149792ea63850

```auto
{
    "coverId": "018f63b126f87044b069f89fdf3f55ef"
}

```
