Get News using REST API
-
16-02-2021 - |
Pergunta
I have a working REST query that grabs all News Posts and News Links. Since the former is considered 'Internal' news, I need a query that can grab these two types of news separately.
https://tenanturl.sharepoint.com/sites/intranet/_api/web/lists/getbytitle('Site%20Pages')/items?$filter=PromotedState%20eq%202&$select=Title,file/ServerRelativeUrl,BannerImageUrl,Modified,Description&$expand=file&$orderby=Created%20desc
I see in the Site Pages settings that there are 2 content types:
Can I use the content type within the REST query to split the News results apart? I also notice the _OriginalSourceURL is populated for News Links (External), but any attempt to use that in a REST query filter says it doesn't exist:
Column '_OriginalSourceUrl' does not exist. It may have been deleted by another user.
Solução
You can provide a filter on the Content Type like this:
https://tenanturl.sharepoint.com/sites/intranet/_api/web/lists/getbytitle('Site Pages')/items?$filter=PromotedState eq 2 and ContentType eq 'Repost Page'&$select=Title,file/ServerRelativeUrl,BannerImageUrl,Modified,Description&$expand=file&$orderby=Created desc
The key portion above being the ContentType eq 'Repost Page'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange