Invalid Container. Valid values are RECTANGULAR or NONRECTANGULAR.

Make sure to set the container parameter on the shipment object:

<?php
$shipment->setParameter('container', 'RECTANGULAR');