Search code examples
javascriptnode.jsgetstream-io

get foreignId Data from the feed of a user [Stream Js]


hi i'm trying to implement getstream.io in my project.
i'm using https://github.com/GetStream/stream-js

as my server side script is in nodeJS.
i'm able to create a user in feed using

user1 = client.feed('user', 'dpz');


i'm creating activity for this user using using

activity ={
         "actor":"user:1",
         "message": "@flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
         "verb":"tweet",
         "object":"tweet:4",
         "foreign_id": "flat:4"
         };
user1.addActivity(activity);



if i want to get all records of that user, i use

user1.get()
.then(function(body) { console.log(JSON.stringify(body)); })
.catch(function(reason) { console.log(JSON.stringify(reason.error));});


i get result as :

{"duration":"19ms",
"next":"",
"results":[{
        "actor":"user:1",
        "foreign_id":"flat:4",
        "id":"41231d40-ca5a-11e5-8080-800047dac62a",
        "message":"@flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
        "object":"tweet:4",
        "origin":null,
        "target":null,
        "time":"2016-02-03T09:41:09.335584",
        "to":[],
        "verb":"tweet"
    }]
}


in your rest_ documentation https://getstream.io/docs_rest/#feed_detail


you have specified

feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/



to delete an activity for if the foreign key matches criteria. in your nodejs code

user1.removeActivity({foreignId: 'flat:4'})

line works to remove the feed for that user where foreign key is flat:4



user1.get({foreignId: 'flat:4'})

does not work
can you please help if i want to get feeds with the foreignId as 'flat:4'

is there any way for such ?
please help as i'm stuck on this point only.


Solution

  • The feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/ endpoint is only for DELETE requests. At this present is not possible to retrieve activities by its foreign_id. That field can only be used to perform cascaded deletion and/or to define the uniqueness of your data.

    Looking at the code that you added, it seems like to use references to feeds as the value for foreign_ids, if that's the case then you are probably using this field in a weird/wrong way and you should create a new question on SO to ask help with the integration of your data.