+ Start a Discussion
MellycooksMellycooks 

Filtering Chatter Feed by Group ID AND User ID?

Is there a way to  filter a chatter feed by group id and user id using the Chatter API?  I want to pull just a specific user's posts out of a group feed.
Best Answer chosen by Mellycooks
alouie_sfdcalouie_sfdc
Cool! Another option is that you can use the Salesforce REST API to make the more precise SOQL query on CreatedById:

An example is:

GET /services/data/v33.0/query?q=SELECT+Id+FROM+FeedItem+ ...

Here's the documentation for the query resource (https://www.salesforce.com/us/developer/docs/api_rest/Content/resources_query.htm).



 

All Answers

dchaidchai
Hi Mellycooks,

I'm not aware of a way to filter a Chatter feed by both group id and user id (at the same time); however, here is an alternative that might achieve a similar result to what you are looking for.

With the Chatter REST API, you can search within a particular group's feed for posts containing the user's name as follows:
/chatter/feeds/record/<group id>/feed-elements?q=firstname+lastname

And here is a useful link with some additional information:
http://www.salesforce.com/us/developer/docs/chatterapi/Content/connect_resource_feeds_record.htm#cc_record_feed_elements

Hope this helps!

 
MellycooksMellycooks
Thanks, that works, though it depends on not having users with the same first/last name  pairing.  I do wish the filtering were a bit more robust via the API.

:)
dchaidchai
If you have sufficient rights, the following SOQL query should be able to filter posts (feed items) made within in a group by a user via the group id and user id.

SELECT Id, Body FROM FeedItem WHERE ParentId = '<group id>' AND CreatedById = '<user id>'

This returns the Id and Body fields but you can include additional fields in the result set as described in: 
https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_feeditem.htm

And if you would like to work with the Chatter REST API after, you could then pass the ids from the SOQL result to the feed elements batch get resource.

http://www.salesforce.com/us/developer/docs/chatterapi/Content/connect_resources_feed_element_batch.htm
alouie_sfdcalouie_sfdc
If you're wanting to do this from Apex, you can execute a SOQL query on FeedItem as mentioned above, or you can also do a similar query on CollaborationGroupFeed (https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_collaborationgroupfeed.htm) if you need to use a non-admin user (this way, you can avoid having to filter by the feed item's ID).

And then if you need the Connect API feed item objects because you need richer, structured information, you can pass the feed item IDs you retrieved from your SOQL query into the ConnectApi.ChatterFeeds.getFeedElementBatch() (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_getFeedElementBatch_1) method.
MellycooksMellycooks
Thanks all for the responses.  This is for our mobile app, and we're currently pretty locked in to a REST architecture and this is one of the few places where the font end is using a standard SF API, rather then our custom REST API, so for now we're using the first+last name search within the group.

If that becomes untennable, I will likely switch to a custom endpoint so that I can filter to my hearts desire.  Thanks again!
 
alouie_sfdcalouie_sfdc
Cool! Another option is that you can use the Salesforce REST API to make the more precise SOQL query on CreatedById:

An example is:

GET /services/data/v33.0/query?q=SELECT+Id+FROM+FeedItem+ ...

Here's the documentation for the query resource (https://www.salesforce.com/us/developer/docs/api_rest/Content/resources_query.htm).



 
This was selected as the best answer
MellycooksMellycooks
Oh snap!  I can't believe I didn't know you could do that.  Thanks!