The way to do this is using MACRO B. This means you'd have to have industrial.
https://www.amazon.com/Fanuc-Custom-Macros-Peter-Smid/dp/0831131578Above I've linked you to the reference material MACH's MACROB adheres to.
I'm relatively sure the API call not working as you'd expect is due to the trajectory planner. (Note: The API does state this call cannot be used during GCODE execution.)
For instance, when the planner gets to the point where it's lookahead sees the macro it cannot look into the macro and predict the line you're attempting to go to.
Whereas using the MACRO B function GOTO the planner can see that and interpret it, then plan accordingly.
Perhaps you can use a #VAR if you need to change the line it's going to. I'm not going to pretend to be an authority on this matter though and smurf would likely give a much better explination
Hope this helps!