Application for such writ shall be made by petition to any judge of the supreme court, signed and verified either by the party for whose relief it is intended, or by some person in his behalf, as follows: to the supreme or district court or to any judge thereof, being within the district where the prisoner is detained; or if there is no such officer within such district, or if he be absent or from any cause is incapable of acting, or has refused to grant such writ, then to some officer having such authority residing in any other district.
NMS § 44-1-3