Hi Ayush Jain Thanks for reaching out. You can use the following code to generate the encode sharing url required for the permission : grant API
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
In the above code sharing url is the complete web path of the drive item, which can be obtained from webUrl property returned from the below endpoint GET /drives/{drive-id}/items/{item-id} or as mentioned in your case users/{user-id}/drive/items/{item-id}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment"