We test a model recently proposed for the persistent hard X-ray emission from magnetars. In the model, hard X-rays are produced by a decelerating electron-positron flow in the closed magnetosphere. The flow decelerates as it radiates its energy away via resonant scattering of soft X-rays, then it reaches the top of the magnetic loop and annihilates there. We test the model against observations of three magnetars: 4U 0142+61, 1RXS J1708-4009, and 1E 1841-045. We find that the model successfully fits the observed phase-resolved spectra. We derive constraints on the angle between the rotational and magnetic axes of the neutron star, the object inclination to the line of sight, and the size of the active twisted region filled with the plasma flow. Using the fit of the hard X-ray component of the magnetar spectrum, we revisit the remaining soft X-ray component. We find that it can be explained by a modified two-temperature blackbody model. The hotter blackbody is consistent with a hot spot covering 1-10% of the neutron star surface. Such a hot spot is expected at the base of the magnetospheric e+- outflow, as some particles created in the e+- discharge flow back and bombard the stellar surface.