Hi @Oleksandr
For this problem, you can try the following two approaches.
According to the documentation, you need to first create a shared link for the DriveItem that you want to share, and then encode that link.
When you create a shared link, shareId is also returned, and according to the documentation, you can also use shareId for access.
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.