0
<route url="/V2/order/:orderId" method="GET"> <service 
class="Custom\Test\Api\OrderDetailsRepositoryInterface" method="getOrderDetails"/> 
<resources> <resource ref="self" /> </resources> <data> <parameter name="customerId" 
force="true">%customer_id%</parameter> </data> </route> 

Using this for getorderDetails thought order Id In my module function using this

$orderId = 219;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);
$custLastName = $orders->getCustomerLastname();
print_r($custLastName)

But getting this issue

 "message": "No such entity with %fieldName = %fieldValue",
"parameters": {
    "fieldName": "orderId",
    "fieldValue": null
},

Steps to reproduce:

  • Headers: Authorization Bearer + [TOKEN]
  • Create a order with get /V2/order/219

How can i solve?? it's a bug or i forgot something? i've seen a lot of thread but no one can help me.

Thanks in advance!

0

try below code

<route url="/V2/order/:orderId" method="GET"> 
    <service class="Custom\Test\Api\OrderDetailsRepositoryInterface" method="getOrderDetails"/> 
    <resources> 
        <resource ref="self" /> 
    </resources> 
    <data> 
        <parameter name="customerId" force="true">%customer_id%</parameter> 
    </data> 
</route> 

etc/di.xml

<preference for="Custom\Test\Api\OrderDetailsRepositoryInterface" type="Custom\Test\Model\OrderDetailsRepository" />

OrderDetailsRepositoryInterface.php

namespace Custom\Test\Api;

use Magento\Framework\Api\SearchCriteriaInterface;

/**
 * Order repository interface.
 * @api
 * @version : 1.0
 */
interface OrderDetailsRepositoryInterface
{
    
    /**
     *
     * @param int $orderId
     * @param int $customerId
     * @return mixed[]
     */
    public function getOrderDetails($orderId, $customerId);
}

OrderDetailsRepository.php

namespace Custom\Test\Api;

use Custom\Test\Api\OrderDetailsRepositoryInterfac;

class OrderDetailsRepository implements OrderDetailsRepositoryInterfac
{

    protected $order;

    public function __construct(
        \Magento\Sales\Api\Data\OrderInterface $order
    ) {
        $this->_order = $order;
    }

    /**
     * {@inheritdoc}
     */
    public function getOrderDetails($orderId, $customerId)
    {
        $response = [];
        $order = $this->_order->load($orderId);
        if (is_object($order) && $order->getId() > 0)
            $response['increment_id'] = $order->getIncrementId();
        echo "<PRE>";
        print_r($response);
    }
}
  1. Headers: Authorization Bearer + [CUSTOMER TOKEN]

url = http://127.0.0.1/rest/V2/order/219

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.