How to add sales order status history data programmatically in Magento 2?

To add sales order status history records to the given order, you required order id, status, comment message, is customer notify and entity name to insert entry on the sales_order_status_history table.

Create a factory object for the class Magento\Sales\Model\Order\Status\History and save the object data using the Order Status History Repository Interface.

I hope you have all the needed data to create an entry for the sales_order_status_history table for an order.

In the above method, all the required field is self-explanatory. You can add any status for the comment, boolean value for the customer notify and parent id is the order main id.

Once the code runs successful, New Entry inserted to the table with the given order.

You can Add Status History Comment to the order by Order id in Magento 2.