Zend certified PHP/Magento developer

magento 2.4.2 add custom attribute in order api only

On my magento, I’ve created a custom attribute for the order and a custom attribute for the order items. In order to show these on the order api, I’ve placed my two attributes in an extension_attributes.xml and added the relative plugins for the OrderInterface and the OrderItemInterface. This modification works: if I call the orders api, I can see my two attributes in the relative extension_attributes key.

Now I’d like to summarize these two values in only one key called “description”. This new key should not be present in the order object but only in the order api.

So my questions are:

  • is there a way to add a key to the order api without creating the corresponding field in the order object?
  • is there a way for the description key to be outside the “extension_attributes”?

Basically, my json should look something like this:

{
    "base_currency_code": "USD",
    "base_discount_amount": 0,
    "base_grand_total": 1994.43,
    .... // all the other order information
    "description": "..." // this is where the new key is supposed to go instead of being  inside the extension_attributes key
 }