The legumes were introduced in the episode Garage Sale. Jim explains that he bought them on a vacation in Jamaica. The packet of legumes mysteriously appear on Jim and Pam's desk in the warehouse, and Dwight takes an interest in it. Although Dwight at first doesn't believe that the legumes have any real magic powers, he is convinced of it when they later appear again, after Jim having destroyed them earlier. He trades his telescope for the legumes and can later be seen planting them outside the warehouse, where Jim then substitutes the planted legumes for fully grown plants, further deceiving Dwight into thinking they really are magical.
Professor Copperfield's Miracle Legumes are a reference to the magical beans in Jack and the Beanstalk.