A U.S. appeals court in New York ruled Thursday that the National Security Agency's program to collect phone records of Americans is illegal.

The program collected “metadata” from millions of phone calls from American citizens. The metadata recorded the times when the phone calls were made and the phone numbers called.

The surveillance program was not known to the public until two years ago. NSA contractor Edward Snowden leaked the information about the program to reporters in June of 2013.

The NSA claimed that the spying program was legal under the Patriot Act, which Congress passed following the September 11 terrorist attacks.

The appeals court ruled that the spying program was not authorized by Congress. The three-judge panel of the court wrote,”Congress cannot reasonably be said to have ratified a progam of which many members of Congress - and all members of the public - were not aware."