# How to access older version of order via API

**URL:** <https://forum.shopware.com/t/how-to-access-older-version-of-order-via-api/104438>\
**Category:** Programming (EN)\
**Created:** [2. Juli 2024 um 17:47 UTC](https://forum.shopware.com/t/how-to-access-older-version-of-order-via-api/104438 "2024-07-02T17:47:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@steven](https://forum.shopware.com/u/steven)\
**Post date:** [2. Juli 2024 um 17:47 UTC](https://forum.shopware.com/t/how-to-access-older-version-of-order-via-api/104438/1 "2024-07-02T17:47:08Z")

</div>

I am using the endpoint /api/search/order to gain data for an export. As i need older versions of a specific order, i am trying to search with the versionId (which i know from the documents endpoint and which i also find in the database for the specific order).  
Using the following filter I get zero results.

{  
„filter“: [  
{  
„type“: „equals“,  
„field“: „versionId“,  
„value“: „0190737f9592733b9322b9e3e0742f0a“  
},  
{  
„type“: „equals“,  
„field“: „id“,  
„value“: „019072b4aabb7015b45701e75c8cac8c“  
}  
]  
}

Is there any point where I have to activate the API-output of versioned entities or do i have to add futher data to the request?

---

<div class="post-metadata">

**Author:** ![chamaw](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@chamaw](https://forum.shopware.com/u/chamaw)\
**Post date:** [4. Juli 2024 um 06:36 UTC](https://forum.shopware.com/t/how-to-access-older-version-of-order-via-api/104438/2 "2024-07-04T06:36:21Z")

</div>

this is really a „hard one“ I can remember I was looking for hours on this. But at the end it is easy:

The solutions uses the context. So use the context you already have and use the method createWithVersionId

```auto
$contextHistorical = $contextLiveVersion->createWithVersionId($versionId);

```

now you can use $contextHistorical with the orderId to search and fetch the data

```auto
$order = $this->fetchOrder($orderId, $context);

```

here is the fetchOrder Method:

```auto
private function fetchOrder(string $orderId, Context $context)
    {
        $criteria = (new Criteria([$orderId]))
            ->addAssociation('lineItems')
            ->addAssociation('transactions')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('deliveries.positions.orderLineItem')
            ->addAssociation('deliveries.shippingOrderAddress.country')
            ->addAssociation('deliveries.shippingOrderAddress.countryState');

        return $this->orderRepository
            ->search($criteria, $context)
            ->get($orderId);
    }

```

best

Carsten

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/2/9/29c7587ba660f00e4995d1743162782e5d6d8653.svg) [@system](https://forum.shopware.com/u/system)\
**Post date:** [3. August 2024 um 06:37 UTC](https://forum.shopware.com/t/how-to-access-older-version-of-order-via-api/104438/3 "2024-08-03T06:37:15Z")

</div>

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.
