When using the /questions method to retrieve a particular question, I'd like to also get the display name of the site on which the question is located (e.g., User Experience). At present, the API does not return a site object with this information.

Brock Adams gave an explanation of various ways one can get around this limitation. They work, but I hope that the feature merits consideration for inclusion in a later version of the API.

Original form of the question, to which the answer refers

When using the /questions method to get a particular question, is there a way to also get the display name of the site on which the question is located? The method appears to be able to return site type, but there is no site field nested under question. Am I missing something?

(Incidentally: for migrated questions, one can get the name and other information for the site from which the question came.)

I understand that I can get the site's display name using /sites, but that means making another call just for this small piece of information.

1 Answer 1


You already know the site, it has to be built in to every /questions query. But, if you are querying separate sites with concurrent AJAX queries, merely encapsulate the site name in your AJAX callback. See this Stack Overflow question for an example of doing that in javascript.

Alternatively, you can parse the link property of the question response to determine the site.

EG: The question response returns a link for each question like this:

"link": "http://gaming.stackexchange.com/questions/176660/how-to-configure-applied-en"

So, just extract the domain:

var qLink   = "http://gaming.stackexchange.com/questions/176660/how-to-configure-applied-energistics-to-increase-item-count-to-an-exact-value-wh";
var qDomain = qLink.match (/^https?:\/\/([^\/]+)/i)[1];
// Yields: "gaming.stackexchange.com"

You can then use the domain for the site for subsequent calls:

Per-Site Methods
Each of these methods operates on a single site at a time, identified by the site parameter. This parameter can be the full domain name (ie. "stackoverflow.com"), or a short form identified by api_site_parameter on the site object.

For example, these calls all yield the same results:

(The last 2 domains are aliases for the Gaming site.)

If you really want the English name, EG "Arqade", then look up the domain, as determined above, in a table that your app cached after calling /sites once per app session or once per day.

  • You can get it for migrated sites because they are returned in a site object. The API designers saw no need to return a site object for the question itself. ... As for client-side JS. Either just run /sites once per page load or cache the results in localStorage. It's not hard and works well, on average. Commented Jul 13, 2014 at 1:28

You must log in to answer this question.