There's a code example to do exactly this, in the CodeBank