Get all orders of customer using customer’s token in Magento 2 API

The question:

I want all orders of customer using customer’s Token in Magento API.

Which gives the list of all previous orders of the customer.

This API provides me the cart products of specific customer using customer’s Token.

http://<magento-host>/rest/V1/carts/mine

Authorization :: Bearer <Customer Token>

Thanks in advance!

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You should be able to filter out the orders of a single customer using the search query parameters like this:

https://<mage host>/rest/V1/orders/?searchCriteria[filterGroups][0][filters]
[0][field]=customer_id&searchCriteria[filterGroups][0][filters][0][value]=<customer_id>

This returns a list of orders on which you can loop and find out other information.

Method 2

I think Magento2 doesn’t provide inbuilt functionality for customer token to fetch all orders so you need to implement the same.

And for that, kindly refer below link

https://magento.stackexchange.com/questions/167749/get-pending-completed-processing-orders-rest-api-problem

http://www.ipragmatech.com/extend-magento2-rest-api-easy-steps/

Method 3

Got the solution For this!!

Magento is using resource Magento_Sales::sales because of this we can’t access it using Customer’s token so for the same we need to override Specific API with

<resource ref="self" />

And using this we can access all orders of specific customer using customer’s Token in Magento API.

<route url="/V1/orders" method="GET">
        <service class="MagentoSalesApiOrderRepositoryInterface" method="getList"/>
        <resources>
            <resource ref="self" />
        </resources>
    </route>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment