tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
109 stars 27 forks source link

`/posts`: Broken pagination with `sort: asc` #137

Open marcustyphoon opened 2 months ago

marcustyphoon commented 2 months ago

When using the new sort: asc option on the posts endpoint, a pagination links object is included, but it doesn't actually allow the user to paginate through all of the results, presumably because it's starting from the "end" but is still paginating in descending order.

For example:

curl "https://api.tumblr.com/v2/blog/april/posts?sort=asc&api_key=[removed]"

{
  "meta": {
    "status": 200,
    "msg": "OK"
  },
  "response": {
    "blog": { ... },
    "posts": [ ... ],
    "total_posts": 76220,
    "_links": {
      "next": {
        "href": "/v2/blog/april/posts?sort=asc&tumblelog=april&page_number=VBhXtG4VJ38EJGXha1bRQ01EutiCQ2UjxAbGwDcW2YxDWDlTMDdVSlBzalpnNEJ2bnBwMk1LLzl4eERjUnJoUkFNdysyWWoyNjdNWnR4S2dieGU5aFR5T3JFMVptb0s4aUg5QnE5c0RoTHBETXB0TnNBTElTK0F0c0JXTHJPZkVhaFVlRkZaL3NVRkhXcVF5VVJJcWhEMXRudUNoNFFhaXZxaWlKaXB5MkJUZHJxR1YrdFVjMkdzUTJCT3B0engvNGM4dU5McjZtSlIwd1dlZVFtRVlMSTM4MG8wb0JuL0ZJVDFpUmoyTHQwU3g1UHRxM241NlBQOXh3amNBU1Z4Z1A0SkJzTWJ5b25TT0VXbzlydTNXL1dQd3JPa2tjK1dadW5FNXM4bkcrVU51YWpYT1VCbWJ1MVUrcjlheVg2M3Z1VWNvSVpJVE9mMTBkUnU1ckc4WVJsb3JjWmp4REh3WmpCcTRyUk96WWhIYVlCejgwQkcrN0JFUG5hekJmQWZMcmxJQW5xZUpJbnhsTUF0Q2xMRnZobkd0N3BLRnBIN2Q2SmtHaW4vc3BsVU54b3pDaFUvaDZtdz09",
        "method": "GET",
        "query_params": {
          "sort": "asc",
          "tumblelog": "april",
          "page_number": "VBhXtG4VJ38EJGXha1bRQ01EutiCQ2UjxAbGwDcW2YxDWDlTMDdVSlBzalpnNEJ2bnBwMk1LLzl4eERjUnJoUkFNdysyWWoyNjdNWnR4S2dieGU5aFR5T3JFMVptb0s4aUg5QnE5c0RoTHBETXB0TnNBTElTK0F0c0JXTHJPZkVhaFVlRkZaL3NVRkhXcVF5VVJJcWhEMXRudUNoNFFhaXZxaWlKaXB5MkJUZHJxR1YrdFVjMkdzUTJCT3B0engvNGM4dU5McjZtSlIwd1dlZVFtRVlMSTM4MG8wb0JuL0ZJVDFpUmoyTHQwU3g1UHRxM241NlBQOXh3amNBU1Z4Z1A0SkJzTWJ5b25TT0VXbzlydTNXL1dQd3JPa2tjK1dadW5FNXM4bkcrVU51YWpYT1VCbWJ1MVUrcjlheVg2M3Z1VWNvSVpJVE9mMTBkUnU1ckc4WVJsb3JjWmp4REh3WmpCcTRyUk96WWhIYVlCejgwQkcrN0JFUG5hekJmQWZMcmxJQW5xZUpJbnhsTUF0Q2xMRnZobkd0N3BLRnBIN2Q2SmtHaW4vc3BsVU54b3pDaFUvaDZtdz09"
        }
      }
    }
  }
}                                                                                                                    

and then:

curl "https://api.tumblr.com/v2/blog/april/posts?sort=asc&tumblelog=april&page_number=VBhXtG4VJ38EJGXha1bRQ01EutiCQ2UjxAbGwDcW2YxDWDlTMDdVSlBzalpnNEJ2bnBwMk1LLzl4eERjUnJoUkFNdysyWWoyNjdNWnR4S2dieGU5aFR5T3JFMVptb0s4aUg5QnE5c0RoTHBETXB0TnNBTElTK0F0c0JXTHJPZkVhaFVlRkZaL3NVRkhXcVF5VVJJcWhEMXRudUNoNFFhaXZxaWlKaXB5MkJUZHJxR1YrdFVjMkdzUTJCT3B0engvNGM4dU5McjZtSlIwd1dlZVFtRVlMSTM4MG8wb0JuL0ZJVDFpUmoyTHQwU3g1UHRxM241NlBQOXh3amNBU1Z4Z1A0SkJzTWJ5b25TT0VXbzlydTNXL1dQd3JPa2tjK1dadW5FNXM4bkcrVU51YWpYT1VCbWJ1MVUrcjlheVg2M3Z1VWNvSVpJVE9mMTBkUnU1ckc4WVJsb3JjWmp4REh3WmpCcTRyUk96WWhIYVlCejgwQkcrN0JFUG5hekJmQWZMcmxJQW5xZUpJbnhsTUF0Q2xMRnZobkd0N3BLRnBIN2Q2SmtHaW4vc3BsVU54b3pDaFUvaDZtdz09&api_key=[removed]"

{
  "meta": {
    "status": 200,
    "msg": "OK"
  },
  "response": {
    "blog": { ... },
    "posts": [],
    "total_posts": 76220
  }
}
cyle commented 2 months ago

thanks for reporting this, i've filed an internal ticket for someone to look into this a little more! i think part of the problem is that it's actually supposed to add a "prev" link, since you're paginating "backwards"... which is a little weird to wrap my head around.