You first have to create the InputEvent simply with InputEvent(). Then set the type and device and depending on what the type is: scancode (for keys), button_index (for mouse buttons) and so on.
As example here is the code I used for a game with configurable controls (full source code is here). key_binds is a Dictionary that I used to store the configured key binds. The keys are the action strings and the values are Dictionaries containing type, scancode and button_index.
for action in key_binds.keys():
for i in range(key_binds[action].size()):
var ev = InputEvent()
ev.type = key_binds[action][i]["type"]
if (ev.type==InputEvent.KEY):
ev.scancode = key_binds[action][i]["scancode"]
elif (ev.type==InputEvent.MOUSE_BUTTON):
ev.button_index = key_binds[action][i]["button_index"]
if (!InputMap.action_has_event(action,ev)):
InputMap.action_add_event(action,ev)