API getHeadlines : Uncategorized / Archived

Hello,

It seems there something wrong with getHeadlines API:

For Uncategorized, I used feed_id = 0 and is_cat = 1 and it’s OK, but for Archived, I used feed_id = 0 and is_cat = 0 but it returns nothing. Did I miss something ?

uncategorized is a category

archived could be different id

e: hm, no it should be zero. you could be using is_cat wrong, try not including it instead of passing 0

boolean params are a bit wonky in the api because of reasons

Yes, it’s ok with “uncategorized”. But the problem is with archived. feed_id = 0, is_cat =0, the API returns nothing (for all_articles or unread)
No success with is_cat empty or without is_cat at all.

see above edit

20charrrr

e: as a general advice if you run into api related troubles check how android app does it and whether it works correctly

strange, the app seems to open archived fine. not at my pc right now so can’t investigate, unfortunately

Ok, I’ve tried:

is_cat = “0”
is_cat = 0
is_cat = false

No succes at all :frowning:

does nothing mean INCORRECT_USAGE? then it’s because of this:

https://git.tt-rss.org/fox/tt-rss/src/master/classes/api.php#L189

you’re probably passing feed_id as a numeric zero which is equivalent to false or "" (unless strict type checking is required) which is why this doesn’t work properly. i guess it’s an api bug.

as a workaround you can pass numerics as a string literal, i.e. {...,"feed_id": "0"}

my test request (below) seems to return correct articles:

curl -d '{"sid":"...","op":"getHeadlines","feed_id":"0","is_cat":"0"}'

e: the following implements a better test for this parameter

https://git.tt-rss.org/fox/tt-rss/commit/a291a0c00f827ba58442ecdac6cc195685582664

Here is my JSON, feed_id is a string

{
"show_excerpt" : “1”,
"order_by" : “feed_dates”,
"limit" : 200,
"excerpt_length" : “150”,
"skip" : 0,
"view_mode" : “unread”,
"show_content" : “1”,
"is_cat" : “0”,
"sid" : “…”,
"feed_id" : “0”,
"op" : "getHeadlines"
}

do you have unread archived articles though

Yes, but “all_articles” returns 0 headlines too.

i dunno then, i’ve transcribed your request into CURL and it works fine for me:

curl -d '{"sid":"...","op":"getHeadlines","feed_id":"0","is_cat":"0","order_by":"feed_dates","limit":200,"view_mode":"all_articles","excerpt_length":150,"show_excerpt":1}'

well, at least an API bug was fixed because of this, even if it was actually unrelated.

Ok, I’ve found the problem. For Archived, getHeadlines returns “feed_id”: null instead of “feed_id”: “0” (or 0), so my app considers that the response is invalid.

you mean for individual articles? this makes some amount of sense because that’s what they are, feedless.

regardless, this probably should be converted to 0 for consistency.

e: https://git.tt-rss.org/fox/tt-rss/commit/2ab49fec9a01d263b2334b20135847552b7d84ed

e2: in general its probably not the best idea to enforce such strict type checking on JSON which is designed to be somewhat flexible about data types because of its roots (which is both good and bad).

i.e in this specific case null in JSON is technically equivalent to 0.

Yes, 0 will be be more consistent because we call feed_id = “0” and receive feed_id = null.

In swift, it’s recommended to type all variables (even if Any can be use) because if you try to use wrong type, the compiler will warn you.

So, for example, with feed_id, the code for initialising a Category object looks like

    if let feed_id = json["feed_id"] as? String {
        self.feed_id = Int(feed_id)!
    } else if let feed_id = json["feed_id"] as? Int {
        self.feed_id = feed_id
    } else if json["feed_id"] is NSNull {
        self.feed_id = 0
    }
    else {
        return nil
    }

If feed_id doesn’t exist or is not int, string or null, the object is not created. And, in the app, if you use feed_id, you’re sure that it’s always contains a valid Int value.