Skip to content

Magento 2.4 Rest API Error: Method’s return type must be specified using @return annotation

I had been trying to use rest api for getting Configurable Products (Child products) using the rest API –
https:url//rest/V1/configurable-products/sku/children

But, I am getting this framework error –
“Method’s return type must be specified using @return annotation. See MagentoCatalogModelResourceModelProductCollectionInterceptor::load()”

Log Trace:

“trace”: “#0 /var/www/html/vendor/magento/framework/Reflection/TypeProcessor.php(291): MagentoFrameworkReflectionTypeProcessor->getMethodReturnAnnotation(Object(LaminasCodeReflectionMethodReflection))n#1 /var/www/html/vendor/magento/framework/Reflection/MethodsMap.php(180): MagentoFrameworkReflectionTypeProcessor->getGetterReturnType(Object(LaminasCodeReflectionMethodReflection))n#2 /var/www/html/vendor/magento/framework/Reflection/MethodsMap.php(115): MagentoFrameworkReflectionMethodsMap->getMethodMapViaReflection(‘Magento\Catalog…’)n#3 /var/www/html/vendor/magento/framework/Reflection/DataObjectProcessor.php(83): MagentoFrameworkReflectionMethodsMap->getMethodsMap(‘Magento\Catalog…’)n#4 /var/www/html/vendor/magento/framework/Reflection/CustomAttributesProcessor.php(76): MagentoFrameworkReflectionDataObjectProcessor->buildOutputDataArray(Object(MagentoCatalogModelResourceModelProductCollectionInterceptor), ‘Magento\Catalog…’)n#5 /var/www/html/vendor/magento/framework/Reflection/CustomAttributesProcessor.php(53): MagentoFrameworkReflectionCustomAttributesProcessor->convertCustomAttribute(Object(MagentoFrameworkApiAttributeValue), ‘\Magento\Catalo…’)n#6 /var/www/html/generated/code/Magento/Framework/Reflection/CustomAttributesProcessor/Proxy.php(95): MagentoFrameworkReflectionCustomAttributesProcessor->buildOutputDataArray(Object(MagentoCatalogModelProductInterceptor), ‘\Magento\Catalo…’)n#7 /var/www/html/vendor/magento/framework/Reflection/DataObjectProcessor.php(107): MagentoFrameworkReflectionCustomAttributesProcessorProxy->buildOutputDataArray(Object(MagentoCatalogModelProductInterceptor), ‘\Magento\Catalo…’)n#8 /var/www/html/vendor/magento/framework/Webapi/ServiceOutputProcessor.php(118): MagentoFrameworkReflectionDataObjectProcessor->buildOutputDataArray(Object(MagentoCatalogModelProductInterceptor), ‘\Magento\Catalo…’)n#9 /var/www/html/vendor/magento/framework/Webapi/ServiceOutputProcessor.php(78): MagentoFrameworkWebapiServiceOutputProcessor->convertValue(Array, ‘\Magento\Catalo…’)n#10 /var/www/html/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(97): MagentoFrameworkWebapiServiceOutputProcessor->process(Array, ‘Magento\Configu…’, ‘getChildren’)n#11 /var/www/html/vendor/magento/module-webapi/Controller/Rest.php(188): MagentoWebapiControllerRestSynchronousRequestProcessor->process(Object(MagentoFrameworkWebapiRestRequestProxy))n#12 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoWebapiControllerRest->dispatch(Object(MagentoFrameworkAppRequestHttp))n#13 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): MagentoWebapiControllerRestInterceptor->___callParent(‘dispatch’, Array)n#14 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoWebapiControllerRestInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoFrameworkAppRequestHttp))n#15 /var/www/html/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(23): MagentoWebapiControllerRestInterceptor->___callPlugins(‘dispatch’, Array, Array)n#16 /var/www/html/vendor/magento/framework/App/Http.php(116): MagentoWebapiControllerRestInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))n#17 /var/www/html/vendor/magento/framework/App/Bootstrap.php(264): MagentoFrameworkAppHttp->launch()n#18 /var/www/html/pub/index.php(33): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))n#19 {main}”
}

Upon Investigation, I found that –
In vendormagentomodule-configurable-productModelLinkManagement.php has function “public function getChildren($sku)”. When I change the following line (104) –
$this->dataObjectHelper->populateWithArray($productDataObject,
$attributes, MagentoCatalogApiDataProductInterface::class);

to

$this->dataObjectHelper->populateWithArray($productDataObject,
[], MagentoCatalogApiDataProductInterface::class);

There is no API error anymore, But the API output looks like –

[
{
“sku”: null,
“status”: 1,
“product_links”: [],
“tier_prices”: []
},
{
“sku”: null,
“status”: 1,
“product_links”: [],
“tier_prices”: []
},
{
“sku”: null,
“status”: 1,
“product_links”: [],
“tier_prices”: []
},

]

With no sku info.

What could be the issue here, that I am missing?