I had problems from new with the electric hood - incompetance with the Swedish dealer. Hopefully you have nothing wrong - it does seem to be a substantial piece of engineering used over many years.
This is the only help I can give :-
My technique is to catch the hood coming over to the front and fasten it - not in the rear holes but the holes visible on the front ( loose - still open a glitch ). Then continue closing down the hood ( an electric motor turns a rotating taper spiral ) until a loud " dunk " - this is some sort of sign the position sensor has released ( or something ). Then re-fasten the front hooks in the rear holes, then continue until windows go up.
You can also test opening and closing the hood and flap with the two manual buttons behind the drivers seat, one releases the hood, the other releases the hood flap cannot remember quite which is which. This just shows that that the function is not your problem.
Thirdly there is the manual reset . Go through the whole motion of opening and closing - manually - to ensure all of the sensors go back to zero position.
This often clears a fault.
I also had the manual flap release stick once - a motor connected to two wires that release the flap. Somehow the manual " bolt " had caught , quite by accident when reconnecting the wires I heard a loud click - it was the manual " bolt " suddenly releasing - solved my problem.
Hope some of this helps