Hi I need to get all user name who is celebrating birthday today based on the value in SPS-Birthday field using Rest API?
How to achieve this?
Hi I need to get all user name who is celebrating birthday today based on the value in SPS-Birthday field using Rest API?
How to achieve this?
I think direct it is not possible what you will need first fetch all site users using below REST URL.
Your Site URL + "/_api/web/siteusers"
Then get account name for all users from above response and generate string like below:
var targerUsers = ["i:0#.f|membership|test.onmicrosoft.com","i:0#.f|membership|dtest1.onmicrosoft.com"];
Then pass this variable in below URL:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='SPS-Birthday')?@v=targerUsers
Then in response of above query result filter by your requirement.
You can use in conjunction with SharePoint Search REST API as below:
https://sitecollectionurl/_api/search/query?querytext='*'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&rowlimit=5&selectproperties='PreferredName,WorkEmail,PictureUrl,Title,Department,RefinableDate00,Url'&refinementfilters='RefinableDate00:datetime("2000-02-08")'
Here , source id = guid of the people data source
You need to map the property SPS-Birthday to one the Refinable properties like RefinableDate00. Check below image.
Once done, wait for the crawl to be completed. In SPO, it takes anything between 24 hours to 1 week ( yes 1 freaking week).
Also important thing to note, the Date is stored something like yyyy-mm-dd. Here, yyyy is always the year 2000.
So in the above query you must form a date from today and then append the year 2000 to it.
&refinementfilters='RefinableDate00:datetime("2000-02-08")'
Update as per Danny's comment
So today's value can be fetched as below:
String.format("{0:yyyy}-{0:MM}-{0:dd}",new Date(new Date().setFullYear(2000)) );
Pass this value to the REST api and after that process the JSON results :)
String.format("{0:yyyy}-{0:MM}-{0:dd}",new Date()); sharepoint.stackexchange.com/questions/160806/…
String.format("{0:yyyy}-{0:MM}-{0:dd}",new Date(new Date().setFullYear(2000)) );
momentjs for that, would be awesome if its doable using this way.