11,682 questions
Hi @Sidi_244
You can send a sharing invitation to external users, which will send an email containing a sharing link to the target users. After that, users will be able to click the sharing link to access the shared folder.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewInvitePostRequestBody()
driveRecipient := graphmodels.NewDriveRecipient()
email := "******@contoso.com"
driveRecipient.SetEmail(&email)
recipients := []graphmodels.DriveRecipientable {
driveRecipient,
}
requestBody.SetRecipients(recipients)
message := "Here's the file that we're collaborating on."
requestBody.SetMessage(&message)
requireSignIn := true
requestBody.SetRequireSignIn(&requireSignIn)
sendInvitation := true
requestBody.SetSendInvitation(&sendInvitation)
roles := []string {
"read",
}
requestBody.SetRoles(roles)
password := "password123"
requestBody.SetPassword(&password)
expirationDateTime := "2025-07-15T14:00:00.000Z"
requestBody.SetExpirationDateTime(&expirationDateTime)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
invite, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Invite().PostAsInvitePostResponse(context.Background(), requestBody, nil)
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.