I made a custom REST API on Magento 2. I want some params to be required and other to be no required or accept null. I have the next code:
Api/Order/ShippingInterface
/**
* API00004. Envío de Pedido
* Url Path: /rest/V1/orders/sap/shipping
* Se mandará a este servicio la información cuando un pedido ya ha
* sido enviado.
*
* @api
* @param string IdPedido
* @param string ControlNumber
* @param string UrlFile
* @param string DecodeFile
* @param string[] Trackings
* @return string JSON con Mensaje de Confirmación o Error.
*/
public function set(
$IdPedido = null,
$ControlNumber = null,
$UrlFile = null,
$DecodeFile = null,
$Trackings = null
);
Model/Api/Order/Shipping.php
/**
* API00004. Envío de Pedido
* Url Path: /rest/V1/orders/sap/shipping
* Se mandará a este servicio la información cuando un pedido ya ha
* sido enviado.
*
* @api
* @param string IdPedido
* @param string ControlNumber
* @param string UrlFile
* @param string DecodeFile
* @param string[] Trackings
* @return string JSON con Mensaje de Confirmación o Error.
*/
public function set(
$IdPedido = null,
$ControlNumber = null,
$UrlFile = null,
$DecodeFile = null,
$Trackings = null
){ ... }
But when I send a Json like:
{"IdPedido":null,"ControlNumber":null,"UrlFile":null,"DecodeFile":null,"Trackings":null}
It returns me the next error:
message":"One or more input exceptions have occurred.","errors":[{"message":"%fieldName is a required field.","parameters":{"fieldName":"IdPedido"}},{"message":"%fieldName is a required field.","parameters":{"fieldName":"ControlNumber"}},{"message":"%fieldName is a required field.","parameters":{"fieldName":"UrlFile"}},{"message":"%fieldName is a required field.","parameters":{"fieldName":"DecodeFile"}},{"message":"%fieldName is a required field.","parameters":{"fieldName":"Trackings"}}]
How can I do this?
Thanks.