Invalid results from credit.json

13 views
Skip to first unread message

ThievingSix

unread,
Nov 29, 2011, 2:55:48 PM11/29/11
to Otter API to Topsy
When I query credit.json before doing a bulk search to make sure that
I have enough credits, I get the message that I have no credits
remaining (both in the JSON response and the response headers). BUT,
when I do a search.json (or something similar), I can see in the
headers that I have around 2.8k remaining like I should.

I don't want to really waste a credit to the search.json just to see
my remaining credits.

Is there something I may be doing wrong, or is this indented, or might
it be a bug?

Thanks

ja...@topsy.com

unread,
Nov 29, 2011, 3:35:07 PM11/29/11
to otte...@googlegroups.com

Instead of requesting credit.json and then search.json, just request search.json.
If you are out of credits, search.json will return http status code 503 to let you know and the headers will contain the reset time for your credits.

credit.json probably shouldn't even be an exposed api because its easy to make the mistake of thinking you need to use it and end up doing two requests instead of one which is a waste. The behavior you're seeing can be viewed as a bug or a feature, depending on how you look at it. Without going into implementation details, the short explanation is that credit tracking is not exact, so you should not depend on the numbers and instead just make requests until they fail.

- Jason T.

ThievingSix

unread,
Nov 29, 2011, 4:50:21 PM11/29/11
to Otter API to Topsy
Interesting. So if I wanted to display the remaining credits in a
dashboard type display when the program comes up, I need to make a
bogus search to get that information? I'm not using credit.json to see
if I have credit for every query, just when the program first starts
up.

ja...@topsy.com

unread,
Nov 29, 2011, 5:09:22 PM11/29/11
to otte...@googlegroups.com
----- Original Message -----
> Interesting. So if I wanted to display the remaining credits in a
> dashboard type display when the program comes up, I need to make a
> bogus search to get that information? I'm not using credit.json to see
> if I have credit for every query, just when the program first starts
> up.

OK, I misunderstood then. When you wrote "before doing a bulk search to make sure that I have enough credits", it sounded like you were using it before each batch of search queries. Using credit.json for a dashboard type display is one of the few legit usages. I'll see if I can track down the bug that is causing it to always return 0 remaining credits. I'd still caution that the values returned are not reliable for a variety of good reasons and it is best to ignore them and just make requests.

ThievingSix

unread,
Nov 29, 2011, 6:27:54 PM11/29/11
to Otter API to Topsy
Ok, I will take the results with a grain of salt as it were. But it
would be nice to let the user know if they have (with overwhelming
probability) enough credits to complete their search. I appreciate you
looking into it.
Reply all
Reply to author
Forward
0 new messages