The first one is likely due to the $tradeMode variable not being set - it's got to be either OPEN or SNEAK. If defaults to OPEN if you omit it.
The second one, I just fixed up - when interacting with an entity, the core UI was expecting there to be a market, and was setting up to show a trade screen rather than a cargo screen. You can work around this for now by adding a temporary market to the entity if it doesn't have one, and removing it when you exit the dialog.
Something like:
MarketAPI market = Global.getFactory().createMarket("fake_market", entity.getName(), 0);
market.setFactionId(entity.getFaction().getId());
market.addSubmarket(Submarkets.SUBMARKET_STORAGE);
((StoragePlugin)market.getSubmarket(Submarkets.SUBMARKET_STORAGE).getPlugin()).setPlayerPaidToUnlock(true);
entity.setMarket(market);
That still won't show the cargo screen, though - it should show a market interaction with the entity, but at least it won't crach. The fix I just put in makes it show the cargo screen.