Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
If the request is successful, this method returns an array of sites that were followed.
If an error occurred while following any of the specified sites, this method returns a 207 status code and the response body will contain an array of entries containing error objects and siteIds indicating which sites were unable to be followed.
Example
The following example shows how to follow multiple sites.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Users.Item.FollowedSites.Add;
using Microsoft.Graph.Models;
var requestBody = new AddPostRequestBody
{
Value = new List<Site>
{
new Site
{
Id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
},
new Site
{
Id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851",
},
},
};
// To initialize your graphClient, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].FollowedSites.Add.PostAsAddPostResponseAsync(requestBody);
// 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"
graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphusers.NewAddPostRequestBody()
site := graphmodels.NewSite()
id := "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"
site.SetId(&id)
site1 := graphmodels.NewSite()
id := "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851"
site1.SetId(&id)
value := []graphmodels.Siteable {
site,
site1,
}
requestBody.SetValue(value)
// To initialize your graphClient, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
add, err := graphClient.Users().ByUserId("user-id").FollowedSites().Add().PostAsAddPostResponse(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.users.item.followedsites.add.AddPostRequestBody addPostRequestBody = new com.microsoft.graph.users.item.followedsites.add.AddPostRequestBody();
LinkedList<Site> value = new LinkedList<Site>();
Site site = new Site();
site.setId("contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740");
value.add(site);
Site site1 = new Site();
site1.setId("contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851");
value.add(site1);
addPostRequestBody.setValue(value);
var result = graphClient.users().byUserId("{user-id}").followedSites().add().post(addPostRequestBody);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.users.item.followedsites.add.add_post_request_body import AddPostRequestBody
from msgraph.generated.models.site import Site
# To initialize your graph_client, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AddPostRequestBody(
value = [
Site(
id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
),
Site(
id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851",
),
],
)
result = await graph_client.users.by_user_id('user-id').followed_sites.add.post(request_body)
If an error occurred, it returns the following JSON response
HTTP/1.1 207 Multi-Status
Content-type: application/json
{
"value": [
{
"id": "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,512a596e-90a1-49e3-9b48-bfa80bee8740",
"error": {
"@odata.type": "#oneDrive.error",
"code": "invalidRequest",
"message": "The site Id information that is provided in the request is incorrect",
"innerError": {
"code": "invalidRequest",
"errorType": "expected",
"message": "The site Id information that is provided in the request is incorrect",
"stackTrace": "",
"throwSite": ""
}
}
},
{
"id": "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851",
"webUrl": "http://contoso.sharepoint.com/sites/SiteFollowed2",
"name": "SiteFollowed2",
"sharepointIds": {
"siteId": "da60e844-ba1d-49bc-b4d4-d5e36bae9019",
"siteUrl": "http://contoso.sharepoint.com/sites/SiteFollowed2",
"webId": "0271110f-634f-4300-a841-3a8a2e851851"
},
"siteCollection": {
"hostname": "contoso.sharepoint.com"
}
}
]
}