I have an API end point that accepts a POST request and performs an action. The action is to convert a quote document to an order document. Once the action has completed, a 200 response is sent back with the following body:
{
"value": "{{uniqueIDofCreatedOrder}}"
}
Odata Client throws and error because in the function getResponseAsObject on the ODataResponse class assumes that if the response has the key value the value will be an array.
public function getResponseAsObject($returnType)
{
$class = $returnType;
$result = $this->getBody();
//If more than one object is returned
if (array_key_exists(Constants::ODATA_VALUE, $result)) {
$objArray = array();
foreach ($result[Constants::ODATA_VALUE] as $obj) {
$objArray[] = new $class($obj);
}
return $objArray;
} else {
return [new $class($result)];
}
}
It gives a the unique string to the foreach loop and the loop fails. Note: Constants::ODATA_VALUE is set to 'value'.
I've tried to look for the authoritative specification that defines OData responses but I can't tell what is the official documentation. Does anyone know where to find that and whether it says anything about the possible data types for certain keys in OData responses? If value should be guaranteed to be an array, I'll reach out to the creator of the API. Otherwise, I'll work on a PR to make this function more flexible.
I have an API end point that accepts a POST request and performs an action. The action is to convert a quote document to an order document. Once the action has completed, a 200 response is sent back with the following body:
Odata Client throws and error because in the function
getResponseAsObject
on the ODataResponse class assumes that if the response has the keyvalue
the value will be an array.It gives a the unique string to the foreach loop and the loop fails. Note:
Constants::ODATA_VALUE
is set to 'value'.I've tried to look for the authoritative specification that defines OData responses but I can't tell what is the official documentation. Does anyone know where to find that and whether it says anything about the possible data types for certain keys in OData responses? If value should be guaranteed to be an array, I'll reach out to the creator of the API. Otherwise, I'll work on a PR to make this function more flexible.