‘I have no doubt that you have asked him (the imam) to pray for you.

Al-Mansur narrated that his father’s uncle said, “Once, I went to Imam Ali al-Hadi and said to him, ‘O my master, this man (he meant al-Mutawakkil, the Abbasid caliph) has turned his back to me and stopped my salary, and this is because he knows I have kept to you.’” He asked Imam al-Hadi (a.s.) to intercede for him with al-Mutawakkil. Imam al-Hadi (a.s.) said to him, ‘You shall be satisfied inshallah.’ In the night, the messengers of al-Mutawakkil came to the man and he hastened with them to the caliph. When he got to the palace, al-Fat~h the doorkeeper scolded him for his delay and allowed him to go in to al-Mutawakkil. The caliph received him with smiles saying to him, ‘O Abu Musa, what made you be busy and forget us? Do you need anything from me?’
The man asked for what he needed and for his salary that was stopped. Al-Mutawakkil ordered him to be given more than what he wanted. The man left delightedly. He saw al-Fat~h at the door and said to him, ‘Did Ali bin Muhammad (Imam al-Hadi) come here?’
Al-Fat~h said, ‘No.’
The man said, ‘Did he send a book?’
The doorkeeper said, ‘No.’
The man left and al-Fat~h followed him saying, ‘I have no doubt that you have asked him (the imam) to pray for you. Please, ask him to pray for me!’
The man went to Imam al-Hadi (a.s.), and when he had the honor of being before him, Imam al-Hadi (a.s.) said to him, ‘O Abu Musa, I see satisfaction on your face.’
The man said submissively, ‘It is by your blessing, my master. But, it was said to me that you neither went to him (to al-Mutawakkil) nor did you ask him for anything.’
Imam al-Hadi (a.s.) smiled and said, ‘Allah the Almighty has known from us that we do not resort in serious matters except to Him, and do not rely in misfortunes except on Him. He has accustomed us to His response whenever we ask Him for something, and we fear that if we change, He also will change with us…’ 
The man understood that Imam al-Hadi (a.s.) had prayed Allah for him in loneliness. He said to Imam al-Hadi (a.s.), ‘O my master, al-Fat~h asks you to pray for him.’
Imam al-Hadi (a.s.) did not respond and said, ‘Al-Fat~h believes in us outwardly and avoids us inwardly. We pray for him if he is loyal to Allah, believes in the messenger of Allah (peace be on him and on his progeny), and acknowledges our rights, we the Ahlul Bayt (s).’
The infallible imams (a.s.) prayed Allah for pure persons who believed in Allah, His messenger, and the right of the Ahlul Bayt (s). They did not pray for those who do not believe.
The man asked Imam al-Hadi (a.s.) to teach him a supplication (du’a) that would benefit him and Imam al-Hadi (a.s.) guided him to the following du’a:
“O You, my supply, my hope and reliance, my resort and support, O You One and Unique, O You, Who “say: He, Allah, is One”, O Allah, I ask You by those whom You have not created like them in Your creation, to have blessing on them…and then you ask for your need.” ( Bihar al-Anwar, vol. 13 p.129, al-Amali by as-Saduq.)