It is code used in BFA interface (function seems changed since old game vesions) to change difficulty: https://github.com/tomrus88/BlizzardInterfaceCode/blob/ffbd8a3f993fb455aaff5726a8192b1a6d81f56c/Interface/FrameXML/UnitPopup.lua#L1885
For "DUNGEON_DIFFICULTY":
SetDungeonDifficultyID(difficultyID);
For "RAID_DIFFICULTY":
SetRaidDifficulties(true, difficultyID);
For "LEGACY_RAID_DIFFICULTY":
SetRaidDifficulties(false, difficultyID);
And diffultyID can be found here: https://github.com/tomrus88/BlizzardInterfaceCode/blob/ffbd8a3f993fb455aaff5726a8192b1a6d81f56c/Interface/FrameXML/UnitPopup.lua#L85
["DUNGEON_DIFFICULTY1"] > difficultyID = 1
["DUNGEON_DIFFICULTY2"] > difficultyID = 2
["DUNGEON_DIFFICULTY3"] > difficultyID = 23
["RAID_DIFFICULTY1"] > difficultyID = 14
["RAID_DIFFICULTY2"] > difficultyID = 15
["RAID_DIFFICULTY3"] > difficultyID = 16
["LEGACY_RAID_DIFFICULTY1"] > difficultyID = 3
["LEGACY_RAID_DIFFICULTY2"] > difficultyID = 4
IDs seems unchanged, you can use https://wowpedia.fandom.com/wiki/API_SetRaidDifficultyID
3 → 10 Player
4 → 25 Player
5 → 10 Player (Heroic)
6 → 25 Player (Heroic)
14 → Normal
15 → Heroic
16 → Mythic
Based on wow UI code you code should look like (to use heroic difficulty):
SetRaidDifficulties(true, 15);