Knowing when to use imperfetto or passato prossimo is one of the most difficult aspects of the Italian language, in my opinion.
I have seen many students struggle with this topic. In some cases, they were even advanced students who could use the congiuntivo quite confidently, for example, but would still stumble upon the choice of when to use imperfetto or passato prossimo.