Maya (deceit) means ignorance of one’s own Self! To imagine the Self where it is not, is called maya (deceit). Maya (deceit) means that one cannot see the nature of things as they are but sees them in a different form.
-- Ambalal Muljibhai Patel
The ignorance of the Self or pure consciousness, which is one's true nature and identity, is the origin of Maya. The purpose of Maya is to connect us back to the Self or pure consciousness.
Maya is but the mind, composed of thoughts and consequent emotions. And each thought is an involvement in a particular aspect of outward existence , seeking sensation in the form of pleasure and avoidance of painful ones. The matured mind understands with time and wisdom that all objective pleasures inevitably results in pain and misery in the long run, and thereby seeks happiness and joy of a more permanent nature. This is found to be in the Self itself.
'Purpose of suffering is to connect you to your Self (Awareness). It indicates that you got carried away by all the transient things around you.' - Sri Sri Ravi Shankar