Hi PavelBrokhman-2898,
MS Graph API offers an endpoin that could create sharing link:
Check Create a sharing link
If you're using SharePoint Rest API, then you can take a reference of below blog:
Best Regards,
Baker Kong
If the response is helpful, please click "Accept Answer" and upvote it.