This User Script called Fediverse Redirector auto-redirects all Community, Post, and User pages to your home instance. It works well.
-
Just click install on that page - it will be added to TamperMonkey (or similar).
-
Then click settings (under the script) and enter your home lemmy instance.
And to directly answer your question: the raw code is visible in that repo, so you could explore how the post
redirect query was constructed.
Is there a specific API call you'd like to make?
Maybe someone can reveal that method and endpoint.