Was cocaine ever marketed as a medication?

I do know that heroin addiction came about because they thought it was a treatment for morphine addiction. I was just wondering whether the same is true in the case of cocaine– if its proliferation started out because it was a treatment for something.