1

Is there a way to get all sites of type main_site from the /site method?

If not, what's the best way to get that list? Should I get all sites with a huge pagesize and then filter it in my App?

1 Answer 1

1

Yes, the sites path does not filter results on site_type. But the good news is, the path accepts a pagesize of 999, so you can get all the results at once.

Then you must filter the results in your app. Here's what it looks like in jQuery:

$.ajax ( {
    type:       'GET',
    url:        'https://api.stackexchange.com/2.1/sites?pagesize=999&filter=!6ONhDO.aXP4LU&key=YOUR_APP_KEY',
    dataType:   'JSON',
    cache:      true,
    success:    processSiteListJSON,
    error:      function (err) {
                    alert ("Oopsie! " + err.responseText);
                }
} );

function processSiteListJSON (apiJson) {
    var mainSites = $.map (apiJson.items, function (siteDat) {
        if (siteDat.site_type == "main_site") {
            return siteDat.api_site_parameter;
        }
        return null;
    } );

    console.log ("Main sites are: ", mainSites.sort () );
}


Note that meta.stackoverflow is a special case and is considered a "main" site.

2
  • I think the API should allow filter in sites. Thank you!
    – estebane97
    May 15, 2013 at 9:06
  • You're welcome! You can open a feature request for such a filter/search. I doubt it will get approved, but it doesn't hurt to ask. May 15, 2013 at 9:09

You must log in to answer this question.

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