You get it immediately after beginning a new game. It is part of your trainer card.
In the video game you get it by beginning a game and its in your trainer card. there are two IDs : A ID that you can see in your Trainer card and another is A Secret ID which you can only see in the trainer card by using AR codes or something..
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.