Mattermost Peer-to-Peer Forum

Shouldn't I use `since` parameter for recursive fetch?


#1

Hi,

I’m making a script to fetch all of posts which posted on specified day.

So, I tried to use page and per_page queries to fetch recursively. But I cannot specify the date when the they were created with since query.

Detail are below.

  1. Trying with only ‘per_page’ query
$ curl -X GET -H 'Authorization: Bearer XXXXXXXXX' -i 'http://localhost/api/v4/channels/channelId/posts?per_page=1'

then, I obtained only 1 post.

  1. Trying with since query
$ curl -X GET -H 'Authorization: Bearer XXXXXXXXX' -i 'http://localhost/api/v4/channels/channelId/posts?per_page=1&since=1'

then, I obtained 113 posts ( all of posted were fetched ).

If you have any suggestion to make my script work, please let me know how to use.


#2

Hi @yoh1496,

This thread might help: Getting posts for a channel on a specific date.

Let me know if it doesn’t help and I can ask our developers for more information.


#3

Hi amy.blais,

Thanks for your reply. I read the thread before, and I didn’t understand how to fetch all of posts ( perhaps, there is need to use page parameter iteratively ).

If there are 600 posts in channel, I think you need to request with parameters below.

  • { per_page : 200, page: 0 }
  • { per_page : 200, page: 1 }
  • { per_page : 200, page: 2 }

And I want to specify the since parameter.

  • { since: xxxxxxxxxxxx, per_page: 200, page: 0 }
  • { since: xxxxxxxxxxxx, per_page: 200, page: 1 }

But there is no difference in the results obtained with above 2 parameters.

So, I thought there is no way to use both since and page (or per_page ) parameters and post this thread.

I apologize my explanation is not clear enough. Thanks.


#4

Hi @yoh1496,

Would you like to ask about this in our community server’s Developer channel. That way you’ll get a quicker response from one of our developers (and possibly also from one of our community members who might know the answer). If you need any help, just let me know and I can also post the question there.


#5

Hi amy.blais,

I posted in developer channel.
Thank you for suggestion.


#6

Hi @yoh1496,

Seems like your post didn’t get replies so just letting you know that I also posted your question to “API v4” channel, and I’ll ping a developer if I don’t get responses either.


#7

Hi, @amy.blais,

Thank you for your kindness.

I found workaround for this problem ( per_page query does not work with since parameter ).
So, I don’t care they wouldn’t reply me.

The workaround is to use before query to iterative fetching as below.

Firstly, get initial result with since query.
Secondly, look the newest post in initial result and if it is not newer than specified date, use the ID as before query and request again.

Perhaps It may work.
If it does not work, I’ll post here again.