Neither Aladdin nor Ali Baba were in the original Thousand and One Nights (aka the Arabian Nights). The tales first appeared in the French translation, probably from a Syrian Christian storyteller named Hanna Diyab who lived in Paris from 1708 to 1710.
The Thousand and One Nights has a very long and complex history. It probably grew out of Indian sources from a couple of thousand years ago, translated into Persian in the 6th century CE, and from there into Arabic a couple of hundred years later. Manuscripts spread around the Middle East (centred on Syria and Egypt) for nearly a thousand years more. And it finally entered Europe in the early 18th century, with Antoine Galland’s French translation Les mille et une nuits, contes arabes traduits en français.
For most of the stories’ history, two of its most famous characters were absent. Aladdin and Ali Baba were not in the Sanskrit sources, the Persian translation, or the Arabic versions of the tales. Galland’s translation was their first printed appearances. But! Galland was not the author either.
In 1707, a French traveller in the Middle East named Paul Lucas met a Syrian named Hanna Diyab. Diyab had just left a Maronite monastery in Lebanon and was heading home to Aleppo. He spoke French (having worked with French merchants in the area) and had a unique gift for storytelling. Lucas had connections with the French royal court of Louis XIV, and he invited Diyab to come back with him.
In 1708, Diyab got to Paris and presented himself at court in Versailles. And he also met Antoine Galland. Over the course of a single month, Diyab regaled Galland with tales. They were quite possibly traditional folk tales, but also most likely crafted, embellished, and structured by Diyab. On May 5, 1709, Diyab first told the story of Aladdin. On May 27, Ali Baba debuted.
Galland dutifully wrote these stories down in his diary. He added them to the ninth, tenth, and eleventh volumes of his Thousand and One Nights translation. Diyab received no credit for his contributions. When he left France in 1710 he dropped out of European history entirely. (Galland may have orchestrated his departure – apparently they were both trying for the same position in the French Royal Library.)
Diyab prospered in Aleppo and wrote an extensive autobiography in 1763. It is only from this text, and Galland’s own diary, that we know about his important contribution to world literature.