What is the purpose of prayer?
"A man must be at one with God...How we stand this instant and every instant toward Him matters to us more than anything else in the Universe. This is the fundamental question: Are you in harmony with God? If you are – you are happy."
– Imam Sultan Muhammad Shah Aga Khan III,
(“My Personal Life”, Aga Khan III: Selected Speeches and Writings, ed. K.K. Aziz, 866)
According to the classical tradition of Islamic philosophy (al-Farabi, Ibn Sina, Tusi, Mulla Sadra, etc), Shia Ismaili theology, Greek thought (Plotinus), and Christianity (Aquinas, Augustine), God is eternal and beyond space, time and change. God's creative, sustaining and grace-bestowing act is ever-occurring and no favors, blessings, or grace are ever being withheld by Him. The petitions and requests of created beings cannot cause any change in God's actions – which are eternal and therefore changeless.
"Of the favours of thy Lord We bestow freely on all – These as well as those: The bounties of thy Lord are not withheld."
– Holy Quran 17:20
The purpose of prayer, seeking God's help, petition, personal supplication, etc is to instill humility on the part of the person making the prayer. Prayer allows the person to become more receptive to the flow of Divine mercy and grace that is already and ever occurring. While prayer cannot change or alter God, prayer changes and alters the one who prays - preparing his soul or consciousness to receive the Divine help that is already being sent to them. The only reason why people do not seem to experience the Divine favors at every moment is because there are barriers blocking them from receiving them - barriers in the form of vices like pride, ignorance, bad intentions, and the like. If these barriers were removed, then one would always be experiencing God's mercy, help, favors, and blessings.
"Human souls are therefore varied and differ with respect to their receptivity to the resplendent lights of the Divine Command, just as material objects are variously receptive to the physical light of the sun. [Consider] stones, for example: one [kind] is pitch black, while others are progressively less dark, and their essences are more receptive to illumination, up to translucent glass which receives light from one side and emits from the other."
– Sayyidna Nasir al-Din al-Tusi, (The Paradise of Submission, tr. S.J. Badakhchani, 109)
In a nutshell, one does not pray to somehow compel God to selectively show special favor to them. The goal of prayer is to rehabilitate the person who prays, by untying the spiritual and psychic knots that block the reception of Divine grace from a person's consciousness. One prays to bring oneself into spiritual harmony with God – such that one can experience a greater share of the Divine blessings which are always raining down upon us. Imam ‘Ali ibn Abi Talib tells us that the remembrance of God is what polishes human hearts (souls), allowing them to hear and see after having been deaf and blind to the light of God’s blessings.
"Truly, God has made the Remembrance [of God] (al-dhikr) a polish (jila’) for the hearts, by which they hear after being deaf, and see after being blind and yield after being resistant."
– Imam ‘Ali ibn Abi Talib, (Reza Shah-Kazemi, Justice and Remembrance, 142)