Shopware 6 product api

Viewed 484

Whenever i'm try to create product using product api it will returns below error

{
"status": 0,
"error_response": {
    "errors": [
        {
            "code": "0",
            "status": "500",
            "title": "Internal Server Error",
            "detail": "Malformed UTF-8 characters, possibly incorrectly encoded"
        }
    ]
},
"result": "",
"link": "https://host/api/v3/_action/sync?_response"
}

Anyone help me. Thanks in advance...

1 Answers

If you have an array inside the request you need to json_encode it and than it should work. Thats how i fixed this issue. It would look like this:

$price = [
    "currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca",
    "net" => $net,
    "gross" => $gross,
    "linked" => false
];
$price = json_encode($price);
$product = [
    "id" => str_replace("-","", $productId),
    "productId" => str_replace("-","", $productId),
    "parentId" =>str_replace("-","", $parentId),
    "name" => $name,
    "taxId" => $taxId,
    "productNumber" => $productNumber,
    "minPurchase" => $minPurchase,
    "price" => $price,
    "purchasePrice" => $purchasePrice,
    "stock" => $stock,
    "images" => $images,
    "atributes" => $atributes,
    "categoryId" => "7997459a37f94a75a14d7cbd872a926f"
];
$price = json_encode($price);
Related