Current theories of structure formation predict specific density profiles of galaxy dark matter haloes, and with weak gravitational lensing we can probe these profiles on several scales. On small scales, higher order shape distortions known as flexion add significant detail to the weak lensing measurements. We present here the first detection of a galaxy–galaxy flexion signal in space-based data, obtained using a new Shapelets pipeline introduced here. We combine this higher order lensing signal with shear to constrain the average density profile of the galaxy lenses in the Hubble Space Telescope Cosmic Evolution Survey (COSMOS). We also show that light from nearby bright objects can significantly affect flexion measurements. After correcting for the influence of lens light, we show that the inclusion of flexion provides tighter constraints on density profiles than does shear alone. Finally we find an average density profile consistent with an isothermal sphere.