How to insert current topic id to the first post

I need to embed a iframe to post, and use current topic ID as variable like this:

<iframe src="https://example.net/iframe?topicid=$"></iframe>

The frame will call some API, so topic ID is required.

I’m trying to get topic ID via URL, but cannot get current URL by header referrer because Discourse do not send full patch referrer (you can pass it by putting some meta tag but mobile Safari doesn’t support the “meta referrer” tag).

Is there another way to automatically put current topic ID to post body?

Thanks.

If it’s for multiple posts then using div with data- then it’s easier to use api.onPageChange + querySelectorAll to reverse the iframe.

Not very clear. I just want to embed on first post of some topic.