You get it automatically right after the 8 th Gym.
Source : Personal Experience.
Hope this Helps, and in future pl. avoid asking questions that can be so easily looked up. :)
How to change your username
How to add a user avatar
Why was my post hidden?
Flags vs Downvotes
Official PokemonDb League
Type a Pokemon name, type, move or ability to see instant results.