Magento2 Orders – Declare @return JSON in API

jsonmagento2orders

I'm playing with M2 API. I built a test module that returns specific Order items in JSON format. I set @return as 'string' (see screenshot below).

Problem: I'm getting error: Class string does not exist.

Question: how should I set @return in phpbloc to get it work properly?

enter image description here

Best Answer

Solution: function returns bunch of Order items so this is how @return should look like:

/**
 * Returns order details 
 *
 * @api
 * @param integer $id Order id.
 * @return \Magento\Sales\Api\Data\OrderItemInterface[]
 */

It will automatically returns then in JSON format.

Related Topic