I have been trying to figure out how to add the Noise fcurve modifier to a Simple Deform's angle parameter. When I attempt to do that, I get an error saying that the context is wrong. 

  

    File "C:\Program Files\Blender Foundation\Blender 4.1\4.1\scripts\modules\bpy\ops.py", line 109, in __call__
        ret = _op_call(self.idname_py(), kw)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    RuntimeError: Operator bpy.ops.graph.fmodifier_add.poll() failed, context is incorrect

I have also been looking through the documentation to see if I can change the value of Noise's offset to something random for each object selected. Since it's an f-curve modifier, I'm having trouble knowing how to go about that.

I'm new to programming so I'm sorry if this is a simple answer. I've been struggling so I would appreciate any help. 

Thank you so much!

    def anim_bend(input_name, bend_angle):
        
        obj = bpy.context.active_object
        
        # for each selected object, run this
        for obj in bpy.data.objects:
            if input_name in obj.name:
                
                #select objects individually 
                ob = bpy.context.scene.objects[obj.name]     # get the object
                bpy.ops.object.select_all(action='DESELECT') # deselect all objects
                bpy.context.view_layer.objects.active = ob   # make the current object the active object 
                ob.select_set(True)                          # select the object
                print(obj.name, ": Selected Successfully")
                
                
                modBendName = "SimpleDeform_Bend"
                
                for modifier in obj.modifiers:
                    if modifier.name == modBendName:
                        obj.modifiers.remove(obj.modifiers.get(modBendName))
                        print(obj.name, ": DELETED existing", modBendName)
                        
                modBend = obj.modifiers.new(name= modBendName, type='SIMPLE_DEFORM') # add simple Deform to mesh
                modBend.deform_method = 'BEND'                                       # change deform to bend
                modBend.angle = math.radians(bend_angle)                             # set initial angle before adding animated noise
                modBend.keyframe_insert("angle",frame=0)                             # add key at frame 0
                fNoise = bpy.ops.graph.fmodifier_add(type='NOISE')
                

                print(obj.name, ": Added", modBendName)