Thanks for getting in touch! I’m not sure if this addresses your specific requirement, but my colleague and I did some testing to write an API script to find all project variables and writing the step name in which they’re scoped to. This is using Octopus.Client, an open source .NET framework.
I hope this helps! Let me know if I’ve misunderstood your goals here.