Hi all,
very probably the thing you want to achieve is protected and so you have to take care about "Secure Execution" and "Tainting" or your code will triggers an error like:
"YOUR_ADDON has been blocked from an action only available to the Blizzard UI. You can disable this addon and reload the UI"
For more information you can check this:
https://wow.gamepedia.com/Secure_Execution_and_Tainting
Merry Xmas and Happy New year to everyone.