Just as the title says if the macro that contains the API command has a comand in it that uses a @{target} it the msg.selected will be undefined, i expect this is because the msg.selected is set after the @{target} has been triggered unlike the @{selected}.