You should be able to modify this example:
POST /me/drive/items/{item-id}/invite
Content-type: application/json
{
"recipients": [
{
"email": "user@externaldomain.com"
}
],
"message": "Here's the file that we're collaborating on.",
"requireSignIn": true,
"sendInvitation": true,
"roles": [ "write" ]
}
See: https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0&tabs=http
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".