This works
\newcommand within qrcode.
\documentclass{article}
\usepackage{qrcode}
\newcommand{\aaa}{test1}
\newcommand{\aab}{test2}
\newcommand{\aac}{test3}
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\aaa}
\qrcode[height=5cm]{www.domain.tld/\aab}
\qrcode[height=5cm]{www.domain.tld/\aac}
\end{document}
This works too
\newcommand with argument within qrcode.
\documentclass{article}
\usepackage{qrcode}
\newcommand{\mylink}[1]{#1}
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\mylink{test1}}
\qrcode[height=5cm]{www.domain.tld/\mylink{test2}}
\qrcode[height=5cm]{www.domain.tld/\mylink{test3}}
\end{document}
This doesn't work
\newcommand with argument (which contains cases) within qrcode.
\documentclass{article}
\usepackage{qrcode}
\usepackage{xstring}
\newcommand{\mylink}[1]{%
\IfEqCase{#1}{%
{1}{test1}%
{2}{test2}%
{3}{test3}%
% you can add more cases here as desired
}[\PackageError{mylink}{Undefined option to tree: #1}{}]%
}%
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\mylink{1}}
\qrcode[height=5cm]{www.domain.tld/\mylink{2}}
\qrcode[height=5cm]{www.domain.tld/\mylink{3}}
\end{document}
How can I fix this?

\mylinkin the\qrcodethe\mylinkmacro is not expanded and that causes an error. A simple solution to this is to force the expansion of\mylinkusing\edef:\edef\mylink#1{\IfEqCase{#1}{<stuff>}[<error_stuff>]}. But that leads to another error in the\IfEqCasemacro, which I could not solve, so I'll leave to someone else. – Phelype Oleinik Jan 15 '18 at 11:36