Where does the unsubscribe link come from in email newsletter?

Hi,

I’m trying to set up an email newsletter with a custom template that I created. And I want to send this newsletter periodically with dynamic content. I’ve thought a solution to do this:

I would create a script that pulls content and author information from my Ghost blog (using the Content API), generates the email template with the custom template I have, and sends an email (through Mailgun API) to each user (whose email information is received through the Admin API).

FIRST QUESTION:
However, I need to have the unsubscribe link that Ghost inserts into newsletters automatically (when you send a newsletter through a post). How do you get the unsubscribe link for a user (whose ID and email I know (through the Admin API))?

The idea is that, if I can generate the unsubscribe link for each user in my script, I can include that in my custom template that I would generate.

SECOND QUESTION:
How can I add functionality to the Ghost Admin page? I would like to give authors this functionality:

Author lists post IDs, my script generates the email template filling in the dynamic content based on the listed post IDs, author views email preview (similar to how you can view an email preview of a post when you create a post).

I know how to create the script that would use the Ghost Admin and Content API and generate the email template. But I don’t know how to add a new custom section on the Ghost admin page.

I was attempting the same thing, more or less, and I was able to generate an unsubscribe link from an email preview of a newsletter post. The link takes the UUIDs (not IDs) for the member and the newsletter which you can grab from your webhook JSON. Note that you have the click “Publish” on the newsletter preview and set it to the appropriate newsletter and then return to the preview in order to get the right link.