# REST API: Artikel anlegen

**URL:** <https://forum.shopware.com/t/rest-api-artikel-anlegen/68251>\
**Category:** Programmierung\
**Created:** [9. Juli 2020 um 14:19 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251 "2020-07-09T14:19:18Z")\
**Posts on this page:** 9\
**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:** [9. Juli 2020 um 14:19 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/1 "2020-07-09T14:19:18Z")

</div>

Hi, ich schaffe es nicht, einen Artikel über die API anzulegen. Das ist meine Php-script:

```
$params = array(
    "name" => $article_name,
    "active" => $article_active,
    "descriptionLong" => $article_descriptionLong,
    "tax" => "7.7",
    "supplier" => $article_supplier,
    "categories" => array(
        "id" => $article_category
    ),
    "mainDetail" => array(
        "number" => $article_number,
        "active" => $article_active,
        "ean" => $article_ean,
        "supplierNumber" => $article_supplierNumber,
        "purchasePrice" => $article_ek,
        "prices" => array(
            array(
                "customerGroupKey" => "EK",
                "price" => $article_vk
            )
        ),
        "attribute" => array(
            "preiscode" => $article_pc,
            "toppreise" => 1
        ),
        "images" => array(
            "link" => $article_img
        ),
        "filterGroupId" => $article_filterSet,
        "propertyValues" => array(
            array(
                "option" => "Veröffentlichung",
                "value" => $article_filterValueRelease
            ),
            array(
                "option" => "Discs",
                "value" => $article_filterValueDisc
            ),
            array(
                "option" => "Medium",
                "value" => $article_filterValueMedium
            )
        )
    )
);
print("".print_r($params,true)."");

$client->put('articles/',$params);

```

Zu jeder Variable gibt es einen Eintrag den ich mir ausgeben lasse. In der Datenbank kommt allerdings nichts an? Habe auch schon „post“ statt „put“ genommen, aber es macht keinen Unterschied

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. Juli 2020 um 06:46 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/2 "2020-07-10T06:46:01Z")

</div>

Ich habe die Params etwas reduziert, so wie das Beispiel auf [https://developers.shopware.com/developers-guide/rest-api/examples/article/](https://developers.shopware.com/developers-guide/rest-api/examples/article/)&nbsp;

- $client-\>put(„articles/“,$params)

- $client-\>put(„articles“,$params)

- $client-\>post(„articles/“,$params)

- $client-\>put(„articles“,$params)

Die Felder werde auch gefüllt.&nbsp;

```
Array
(
    [name] => Rapunzel - Neu Verföhnt - Disney Classics 50
    [active] => true
    [tax] => 7.7
    [supplier] => Walt Disney
    [categories] => Array
        (
            [id] => 79
        )

    [mainDetail] => Array
        (
            [number] => 10076854
            [active] => true
            [prices] => Array
                (
                    [0] => Array
                        (
                            [customerGroupKey] => EK
                            [price] => 9.9
                        )

                )

        )

)

```

Es passiert aber nichts. Was mache ich hier falsch?

Danke und Gruss

---

<div class="post-metadata">

**Author:** ![R4M](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/r4m/32/9983_2.png) [@R4M](https://forum.shopware.com/u/R4M)\
**Post date:** [10. Juli 2020 um 06:53 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/3 "2020-07-10T06:53:22Z")

</div>

> $client-\>put(‚articles/‘,$params);

Hm, zum anlegen benutzt mal eigentlich nur „post“. Ich würde mir die Info vom Shop mal anzeigen lassen:

```
$out = $client->post('articles/',$params);
print_r( $out );

```

&nbsp;

---

<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. Juli 2020 um 07:48 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/4 "2020-07-10T07:48:04Z")

</div>

Super, @R4M‍ Der Tip mit dem output ist echt gut, klappt jedoch nicht wenn man eine falsche Struktur übergibt.

Für Interessierte: Falsch war bei mir,&nbsp;jetzt korrekt:

- $client-\>post(“articles/”,$params)
- “categories” =\> array(array(id=\>213))&nbsp; - zusätzliches Array
- "images =\> array(array(link=http…))&nbsp; - zusätzliches Array&nbsp;sowie im Stamm-Array und nicht in mainDetailarray
- “filterGroupID” muss im Stamm-Arry und nicht in mainDetail-Array
- “properyValues” =\> array(array(“option” =\> array(“name”=\>“Discs”),“value” =\> 123))&nbsp;&nbsp; - zusätzliches Array muss auch im Stammarray stehen

---

<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. Juli 2020 um 12:22 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/5 "2020-07-10T12:22:25Z")

</div>

@R4M‍ Ich habe mal noch eine Frage zu Umlauten als Gruppenname/Optionsname&nbsp;der Eigenschaften

```
"propertyValues" => array(
    array(
        "option" => array(
            "name" => "Veröffentlichung"
        ),
        "value" => $article_filterValueRelease
    )
)

```

Wenn ich „ö“ in Veröggentlichung habe, dann importiert er nicht und gibt einen Fehler zurück? tax, maindetail und number würden fehlen

Habe schon in der PHP Datei folgendes geschrieben:

```
 header('Content-Type: text/html; charset=utf-8');

```

Wenn ich das in der PHP ausgebe mit&nbsp;

```
 print("

    ".print\_r($params,true)."

");

```

kommt bei mir Ver?ffentlichung in einer schwarzen Raute. Was allerding auch nicht der Browserausgabe entspricht und doch in der API selbst nicht auftreten dürte oder?

&nbsp;

---

<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. Juli 2020 um 12:31 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/6 "2020-07-10T12:31:11Z")

</div>

Gelöst, Umlaute kann die API &nbsp;Habe in der DB die ID gesucht und dann id statt name genommen.

---

<div class="post-metadata">

**Author:** ![R4M](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/r4m/32/9983_2.png) [@R4M](https://forum.shopware.com/u/R4M)\
**Post date:** [10. Juli 2020 um 12:36 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/7 "2020-07-10T12:36:52Z")

</div>

Ich baue aktuell an einer Schnittstelle mit mit dieser API zusammen läuft. Umlaute sollte da schon gehen 🙂

---

<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. Juli 2020 um 12:46 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/8 "2020-07-10T12:46:03Z")

</div>

als “value” funktioniert es, aber nicht als “name”

---

<div class="post-metadata">

**Author:** ![R4M](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/r4m/32/9983_2.png) [@R4M](https://forum.shopware.com/u/R4M)\
**Post date:** [10. Juli 2020 um 13:40 UTC](https://forum.shopware.com/t/rest-api-artikel-anlegen/68251/9 "2020-07-10T13:40:37Z")

</div>

Oha, gut zu wissen.
