It only works when the needle or stimulation occurs at the right point(s). Sham acupuncture at deliberately incorrect locations does not work. Endorphins may not even be involved in the therapeutic response, and certainly aren’t when the treated condition has nothing to do with pain.
The analgesic (pain-killing) action of acupuncture is associated with the release of natural endorphins in the brain. This action has no relevance to node sites as claimed by the pseudoscience of acupuncture.