Search code examples
shopwareshopware6shopware6-api

How to update or add tracking codes to shopware 6 order via API?


I want to update or add tracking codes to orders in shopware, the same way that it is done in the admin panel via the API. Admin panel field to add or update tracking codes

First Try I first tried copying the payload used by the admin panel Payload of the admin panel I got this error error from copied payload Second Try 2. I tried using the patch method from the documentation Patch Request I got this error error in the admin panel

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://(domain)/69d9897fb4db7b7c9c28.worker.js.map"" at /home/schcmjkg/staging/vendor/symfony/http-kernel/EventListener/RouterListener.php line 135 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for "GET https://(domain)/69d9897fb4db7b7c9c28.worker.js.map" at /home/schcmjkg/staging/vendor/symfony/http-kernel/EventListener/RouterListener.php:135)\n[previous exception] [object] (Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): No routes found for "/69d9897fb4db7b7c9c28.worker.js.map/". at /home/schcmjkg/staging/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php:74)"} []

But the tracking codes were added everytime(not updated), which gave the error i presume. enter image description here I could add the other images but bascically te-he same order ended up with different tracking codes with same shipping ids


Solution

  • First you'll have to fetch the id of the order_delivery associated with the order.

    GET /api/order/{orderId}?associations[deliveries][]&includes[order][]=deliveries&includes[order_delivery][]=id
    

    Response example:

    {
        "data": {
            "deliveries": [
                {
                    "id": "9d1994d328b44f3e941c9484415ec95c",
                    "apiAlias": "order_delivery"
                }
            ],
            "apiAlias": "order"
        }
    }
    

    Take the id from the response and use it to update the order_delivery record.

    PATCH /api/order-delivery/9d1994d328b44f3e941c9484415ec95c
    

    Request body:

    {
      "trackingCodes": ["foobar"]
    }