Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I am trying to use /questions/{id} API to get a list of questions by their ids. Help page for this request does not indicate the maximum number of ids that can be passed in. Pagesize is maximum 100, so I started off with 100 and got a "HTTP Error 400. The request URL is invalid." Same with 50, however 20 is OK.

The question is whether or not there should be a published limit on number of ID parameters on the API help page and what it is. I didn't want to start hitting the server doing a binary search between 20 and 50 and I think it's in the interest of the community to know about how this is supposed to work.

Background I am doing an app that tracks tags that the user is active in over time, so I need to get to the tags (which are in the Question object) by questionId, which is in the Answer object.

So the workflow is currently like this:

  1. Request user's answers by user id - {Number of answers}/100 requests (300 answers - 3 requests).
  2. Requests a list of questions corresponding to each questionId from above. {Number of answers}/20 (20 is the number of requests that I know works) (300 answers - 15 requests).

This is not very efficient so I would like to know what the maximum number is, so I can minimise the number of requests.

Here is a sample URL (462 characters).

Update The failed request is due to a server rejecting a long URL, which is evident due to response code 400 and presence of payload (Also there are no ASP.NET headers on the response, so I think it's one of the proxies rejecting it before it even hits the web server).

The updated question is what is the limit on the URL length for StackApps sites?

share|improve this question
    
Igor, here is the solution i eventually arrived at: stackapps.com/questions/889 –  Sky Sanders Jun 29 '10 at 16:47
add comment

1 Answer

up vote 3 down vote accepted

You can't rely on giant URLs working on the internet in general.

Apache, IIS, and the various browsers all impose some (default or configurable) maximum length restrictions on URLs. Basically, this isn't a feature of just our API.

All that being said, we explicitly reject all requests that have more than MAX_PAGE_SIZE (100 currently, documented on pagesize) ids in a vectorized request with a 400/4006 error.

You can distinguish the two cases (where we explicitly reject, versus a failure earlier in the tool chain) by whether or not a JSON payload is returned with the HTTP error.

share|improve this answer
    
I appreciate the fact that giant URLs are not reliable and vendor specific, but the general consensus is that under anything 1000 characters is OK with most servers in their default configuration. My understanding is that Stack api sites have a more aggressive configuration where a 460 character request fails. –  Igor Zevaka Jun 9 '10 at 3:30
    
@Igor - that is not a consensus, as default ASP.NET installations apparently do not behave that way. Your question is unanswerable anyway, as we can't give a limit in terms of number of ids when the limit is determined by the number of bytes in the url. –  Kevin Montrose Jun 9 '10 at 3:43
    
Fair enough, do you have a figure for the URL length? I'll update the question in the meantime. –  Igor Zevaka Jun 9 '10 at 3:48
    
@Igor - I believe asp.net defaults to 260 for the path, and something like 1k for query strings. This isn't spec'd in the API because we'll change it whenever we please - for one, .NET 4 knocks that up iirc - and relying on it isn't supported. If you receive 400s you suspect are because of path constraints, split into two and try again. Sorry there isn't a better solution. –  Kevin Montrose Jun 9 '10 at 4:08
    
A 4006 error? –  SamB May 1 '11 at 1:59
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .