You should be able to use the same code as the screen_capture demo, with a couple minor adjustments:
(The code works on any Spatial based node)
yield(get_tree(), "idle_frame");
yield(get_tree(), "idle_frame");
var img = get_tree().root.get_texture().get_data();
img.flip_y()
img.save_png("file_path_here");
The only thing that is really different from the demo is how we are getting the viewport. Because we do not have a get_viewport() function for Spatial based nodes, we instead have to get the scene's root and just assume it is a viewport (which 90% of the time it is)