1

There is REST API endpoint for specific order statuses

GET    /V1/orders/:id/statuses

Reference: https://devdocs.magento.com/guides/v2.3/rest/list.html

But I am looking for approach to fetch all available order statuses using REST API because I am working on external system in which I need to fetch the required magento data.

Any help, experience and knowledge sharing would be appreciated

  • Are you want just available order status list? Or Particular order status? – Sweety Masmiya Jul 24 '19 at 6:34
  • All available order statuses list – Muhammad Hasham Jul 24 '19 at 6:37
2

I created module for that, You can follow this steps for that :

Step 1 : Create registration.php file at app/code/RH/OrderStatus

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'RH_OrderStatus',
    __DIR__
);

Step 2 : Create module.xml file at app/code/RH/OrderStatus/etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="RH_OrderStatus" setup_version="1.0.0"/>
</config>

Step 3 : Create webapi.xml file at app/code/RH/OrderStatus/etc

<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
    <route url="/V1/getorderstatus" method="GET">
        <service class="RH\OrderStatus\Api\Getorderstatus" method="getorderstatusarray"/>
        <resources>
            <resource ref="admin"/>
        </resources>
    </route>
</routes>

Step 4 : Create di.xml file at app/code/RH/OrderStatus/etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="RH\OrderStatus\Api\Getorderstatus" type="RH\OrderStatus\Model\GetorderstatusModel" />
</config>

Step 5 : Create Getorderstatus.php file at app/code/RH/OrderStatus/Api

<?php
namespace RH\OrderStatus\Api;
interface Getorderstatus {
    /**
     * @api
     * @return array
     */
    public function getorderstatusarray();
}

Step 6 : Create GetorderstatusModel.php file at app/code/RH/OrderStatus/Model

<?php
namespace RH\OrderStatus\Model;

use RH\OrderStatus\Api\Getorderstatus;

class GetorderstatusModel implements Getorderstatus {

    protected $statusCollectionFactory;
    public function __construct(
        \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $statusCollectionFactory
    ) {
        $this->statusCollectionFactory = $statusCollectionFactory;
    }

    public function getorderstatusarray() {
        $options = $this->statusCollectionFactory->create()->toOptionArray();
        return $options;
    }
}

Now, Go to Admin -> System -> Integrations and Get Access Token value and set authorization value into postman application.

Then, execute {base_url}/rest/V1/getorderstatus this URL in postman.

You will get all order status.

enter image description here Hope, It will helpful for you.

  • 1
    I was looking for rest api endpoints for all available order statuses but there is none. So I decided to made my own custom rest api for all order statuses. I just finished it successfully and just going to share it in answer but you share it before. I did almost the same but you deserve credit. Anyways great work, keep coding :) thanks :) +1 for appreciation. – Muhammad Hasham Jul 24 '19 at 7:14
  • My pleasure :) Happy coding !! – Rohan Hapani Jul 24 '19 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.