How to assign badges with a button click

You have to code it at backend, not on frontend. Also your rest of code is a little bit chaotic. Did you take a look onto the Velo-API-Docs?