# Preis per API aktualisieren - Cannot unset string offsets

**URL:** https://forum.shopware.com/t/preis-per-api-aktualisieren-cannot-unset-string-offsets/100994
**Category:** Programmierung
**Created:** [23. August 2023 um 23:21 UTC](https://forum.shopware.com/t/preis-per-api-aktualisieren-cannot-unset-string-offsets/100994 "2023-08-23T23:21:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![norman.krey](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@norman.krey](https://forum.shopware.com/u/norman.krey)
#### Post date: [23. August 2023 um 23:21 UTC](https://forum.shopware.com/t/preis-per-api-aktualisieren-cannot-unset-string-offsets/100994/1 "2023-08-23T23:21:34Z")

</div>

```auto
function updateProductPrices($apiUrl, $productId, $dataArray) {
    $productData = [
        'price-updates' => [
            'action' => 'upsert',
            'entity' => 'product',
            'payload' => [
                [
                    'id' => $productId,
                    'price' => [
                        'currencyID' => $dataArray['currencyId'],
                        'gross' => $dataArray['gross'],
                        'net' => $dataArray['net'],
                        'linked' => true
                    ]
                ]
            ]
        ]
    ];
    $curl = curl_init();
    curl_setopt_array($curl, [
        CURLOPT_URL => $apiUrl . "/_action/sync",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_HTTPHEADER => [
            "Accept: application/vnd.api+json, application/json",
            "Content-Type: application/json",
            "Authorization: " . getToken($apiUrl)
        ],
        CURLOPT_POSTFIELDS => json_encode($productData)
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);

    if ($err) {
        return "cURL Error #:" . $err;
    } else {
        return $response;
    }
}

```

Ausgabe von print\_r($productData) :

```auto
Array
(
    [price-updates] => Array
        (
            [action] => upsert
            [entity] => product
            [payload] => Array
                (
                    [0] => Array
                        (
                            [id] => 924909bd56684a0bae8e35153a01df97
                            [price] => Array
                                (
                                    [currencyID] => b7d2554b0ce847cd82f3ac9bd1c0dfca
                                    [gross] => 15.95
                                    [net] => 14.906542056075
                                    [linked] => 1
                                )
                        )
                )
        )
)

```

Ich erhalte diese Ausgabe von $response:  
`{"extensions":[],"success":false,"data":{"price-updates":{"extensions":[],"result":[{"entities":[],"errors":[{"code":"0","status":"500","title":"Internal Server Error","detail":"Cannot unset string offsets"}]}]}},"deleted":[],"notFound":[]}`

Kann mir da jemand weiter helfen?

---

<div class="post-metadata">

### Author: ![area-net-gmbh](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/area-net-gmbh/32/21995_2.png) [@area-net-gmbh](https://forum.shopware.com/u/area-net-gmbh)
#### Post date: [24. August 2023 um 05:33 UTC](https://forum.shopware.com/t/preis-per-api-aktualisieren-cannot-unset-string-offsets/100994/2 "2023-08-24T05:33:46Z")

</div>

Fehler deutet darauf hin, dass anstatt einem String ein Array erwartet wird. Versuche mal price als Array zu übergeben - da ja theoretisch mehrere Preise upgedatet werden können:

```auto
'price-updates' => [
            'action' => 'upsert',
            'entity' => 'product',
            'payload' => [
                [
                    'id' => $productId,
                    'price' => [
                       [
                          'currencyID' => $dataArray['currencyId'],
                          'gross' => $dataArray['gross'],
                          'net' => $dataArray['net'],
                          'linked' => true
                       ]
                    ]
                ]
            ]
        ]

```

---

<div class="post-metadata">

### Author: ![norman.krey](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@norman.krey](https://forum.shopware.com/u/norman.krey)
#### Post date: [24. August 2023 um 08:56 UTC](https://forum.shopware.com/t/preis-per-api-aktualisieren-cannot-unset-string-offsets/100994/3 "2023-08-24T08:56:27Z")

</div>

Dankeschön, es war wohl gestern schon zu spät. 😴

Zusätzlich hatte ich auch noch das „D“ bei currencyId groß geschrieben, das konnte er dann auch nicht finden.
