You can buy a CPAP machine without having a sleep test but it’s not recommended. In the first place, you can’t be sure you have sleep apnea without getting a sleep test. Secondly, you won’t know how severe your sleep apnea is, what type it is or how to titrate your machine to suit your needs.
You can easily get a home sleep test and receive your diagnosis without the bother of having to spend a night in a sleep lab. If the sleep test indicates that you do have sleep apnea, you can simply order a CPAP trial so you can trial a machine and mask before you buy. Easy!