Save_dirty api change help

Hey Guys,
I need a little help. With a recent API change in 2.80
bpy.ops.image.save_dirty() was changed to bpy.ops.image.save_all_modified()
Which is fine, except when I run the code I now get the following error:
RuntimeError: Operator bpy.ops.image.save_all_modified.poll() failed, context is incorrect

How can I fix this so that it saves all the textures in the file that have changed?