Search code examples
node.jssharepoint-rest-api

Why User Id gotten from sharepoint siteusers api or clientPeoplePickerSearchUser api different from sharepoint Task AssignedToId?


Im trying to create a task using sharepoint rest api, in doing so Im trying to add assignee as well which is done through adding AssignedToId. The user Id I get for a particular user using the user information api or clientPeoplePickerSearchUser api with site users api (e.g. user retrived with Id 28) is different from what it wants as AssignedToId (AssignedToId it wants is 14) for the same user.

I have tried the api user information api

GET
/_vti_bin/ListData.svc/UserInformationList?$filter=(substringof('" + params.searchKey + "',Name) and ContentType eq 'Person')

And also the clientPeoplePickerSearchUser

POST /_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser
var data = {
                queryParams: {
                    AllowEmailAddresses: true,
                    AllowMultipleEntities: false,
                    AllUrlZones: false,
                    MaximumEntitySuggestions: 50,
                    PrincipalSource: 15,
                    PrincipalType: 15,
                    QueryString: params.searchKey,
                    Required: false,
                    UrlZoneSpecified: false
                }
            }

let users = JSON.parse(createTaskResponse.data.d.ClientPeoplePickerSearchUser)

            // return users
            let userUrl = this.userProvider.resource + "/_api/web/siteusers?"
            let promises = []
            for(let user of users) {
                let actualUrl = userUrl + "Title eq " + user.DisplayText
                console.log('user is: ', user.DisplayText)
                promises.push(axios.get(actualUrl, {
                    headers: headers
                }))
            }

Solution

  • So the issue with my approach was that sharepoint has differnt user ids across base domain/ site and across subsites, so you want to use the actual site url instaed of the base sharepoint url when accessing sharepoint users.