my 2014 528I tells me door not closed when it is closed
Sounds like a bad door sensor. I would just take it back to the dealer since it should be covered under your warranty. However if your battery drains due to the issue and becomes dead you may have to pay for a new one since they are not covered under your warranty.
You could check the driver door jamb for the switch and maybe inspect it if its even visible but its will probly need to be towed to BMW. You could also check the 5 series forums and see if anyone else has had this issue.
Call the place where you bought it, explain the situation and they will likely cover the tow to them to get it fixed. It will be under warranty unless they can prove that someone damaged it and isn't defective.
Looking for a Used 5 Series in your area?
CarGurus has 17,687 nationwide 5 Series listings starting at $1,500.
Search BMW 5 Series Questions
BMW 5 Series Experts