Delete Shipment item record by item id Magento 2.

The shipment item record will be available on the Magento 2 sales_shipment_item table.

The table contains the list of shipment item records with the product item level. When you delete the record, a record will be deleted from the sales_shipment_item table.

If you want to delete shipment item programmatically by delete() method of Shipment Item Repository Interface, You first need to load the shipment item object by shipment item id and pass loaded object to delete method.

<?php
namespace Jesadiya\DeleteShipmentItem\Model;

use Exception;
use Magento\Sales\Api\Data\ShipmentItemInterface;
use Magento\Sales\Api\ShipmentItemRepositoryInterface;
use Psr\Log\LoggerInterface;

class DeleteShipmentItem
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var ShipmentItemRepositoryInterface
     */
    private $shipmentItemRepository;

    public function __construct(
        LoggerInterface $logger,
        ShipmentItemRepositoryInterface $shipmentItem
    ) {
        $this->logger = $logger;
        $this->shipmentItemRepository = $shipmentItemRepository;
    }

    /**
     * Delete shipment item by shipment item id
     *
     * @return bool
     */
    public function deleteShipmentItem(int $shipmentItemId): bool
    {
        $shipmentItemData = false;
        try {
            $shipmentItemData = $this->shipmentItemRepository->get($shipmentItemId);
            if ($shipmentItemData) {
                $this->shipmentItemRepository->delete($shipmentItemData);
            }
        } catch (Exception $exception)  {
            $this->logger->critical($exception->getMessage());
        }
        return $shipmentItemData;
    }

$shipmentItemId = 100;
Use $this->deleteShipmentItem($shipmentItemId) to delete specific shipment item from the shipment item table.

If Item is successfully deleted, the Result will be true otherwise it’s false.