Yes. You may only legally hire an H1B visa holder for a role if you can demonstrate that you made a good faith effort to hire an American (technically someone with full right to work in the US) and couldn’t.
It’s no secret many companies don’t come close to meeting that standard hence the ramp up of enforcement on those violating the terms of these visas. A green card holder would have the same right to the role as a US Citizen but an H1B visa holder is only a secondary option if others couldn’t be hired.