3

I'm trying to fetch card-data as it is fetched on https://stackexchange.com/sites (request example below as a Node.js fetch), but can't find cards (or, hence, card IDs) for CS50 or Programming Language Design and Implementation, so I can't make the request. Both these sites are returned from https://api.stackexchange.com/2.3/sites, so I don't see why they wouldn't be there. Do they have IDs that I can't find or what's going on?

fetch("https://stackexchange.com/sites/card-data", {
  "headers": {
    "accept": "*/*",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
  },
  "body": "siteId={id}&fetchHotQuestion=true&fetchTopUsers=true",
  "method": "POST"
});

Site ID can be found in the HTML for each card, extracting it from the element's ID in the format "gv-site-{id}".

4
  • 2
    I'm unsure what you mean by "card-data". You've put "card-data" in code format, but I don't recall anything that's called that in the SE API, and there's nothing in the page which you've linked which has "card-data" in it, and nothing that seems appropriate even has "card". There are numeric IDs for each site and meta site which are used in some areas of SE (e.g. in the WebSocket), but which aren't included in the SE API. IMO, the easiest place to find those IDs is meta.stackexchange.com/topbar/site-switcher/all-pinnable-sites, which has a full list of those site IDs in JSON.
    – Makyen
    Commented Jun 27, 2023 at 3:14
  • 2
    AFAIK, private betas (Programming Language Design and Implementation) and a few special sites (CS50) are not shown on the site switcher & list by default. Commented Jun 27, 2023 at 3:22
  • 1
    @MetaAndrewT. makes sense. I tried the ID I got from @Makyen's link, which yielded a correct response ({hotQuestionHtml, topUsersHtml}), but "hot question" was just "-" (could be that no questions have been asked there recently). I think this is as far as it'll go. Thanks for the help
    – else
    Commented Jun 27, 2023 at 4:35
  • Related: The single source of truth for the site list Commented Jun 27, 2023 at 11:02

0

You must log in to answer this question.

Browse other questions tagged .