I needed a second key as the car only came with one key, purchased a blank from ebay, it came with the correct chip inside, got it cut by a local shoe repair and key cutting guy, not Timpsons, they didn't want to know. Then tried using an AK90 coding machine, pulled the EWS module from the car and read the processor chip on the board as per the instructions, found it really difficult to get it to read the chip, very hit and miss getting a good connection with the AK90 lead that covers the chip to contact its pins even after cleaning them so there were good connections. Did manage to get it read and coded the new key to an unused key slot but whatever I coded it to resulted in a no crank key. I gave up in the end and had a mobile locksmith come and sort the new key. He used a different method of reading the EWS, using a coding machine costing 3k he tells me. He read the EWS by reading it via the eeprom chip on the board and then using trhe downloaded file coded the key to an unused slot, first go resulted in a no crank key. Had another go and coded it to a slot that was one of the keys I didn't have. Result, a cranking key. Cost me £120 for his expertise, still cheaper than BMW would have charged. Key was then synced with the original key I had by inserting original in ignition turn to ignition then off pulling the key out and holding down the unlock button whilst pressing the lock button three times finally releasing the unlock button. Immediatley after this the second key has to be synced by holding down the unlock button and repeating the three presses of the lock button finally releasing the unlock button, the locks will cycle once each key has been synced to confirm the operation. Just remember the keys must be done immediatly after each other to get them synced, bit of a finger dance if you have more than two keys to sync.
Good sync instruction methods here https://www.youcanic.com/guide/program-bmw-key-fob
If one method fails try the 2nd method.
ebay key I used here https://www.ebay.co.uk/itm/Remote-Key-Fob-433MHz-PCF7935-Chip-HU92-Blade-For-BMW-E46-E39-X3-X5-Z4-Z8-M3-M5/401826468000?hash=item5d8eb950a0:g:cNwAAOSwVTpeFaS4