0

I am using

https://api.stackexchange.com/docs/wikis-by-tags#tags=c%23%3Bsql%3Bexcel%3Bphp&filter=default&site=stackoverflow

and the response is

  "items": [
    {
      "excerpt_last_edit_date": 1638118575,
      "body_last_edit_date": 1638118521,
      "excerpt": "C# (pronounced "see sharp") is a high level, statically typed, multi-paradigm programming language developed by Microsoft. C# code usually targets Microsoft's .NET family of tools and run-times, which include .NET, .NET Framework and Xamarin among others. Use this tag for questions about code written in C# or about C#'s formal specification. ",
      "tag_name": "c#"
    },
    {
      "excerpt_last_edit_date": 1628666337,
      "body_last_edit_date": 1628666337,
      "excerpt": "Only for questions on programming against Excel objects or files, or complex formula development. You may combine the Excel tag with VBA, VSTO, C#, VB.NET, PowerShell, OLE automation, and other programming related tags and questions if applicable.\r\n\r\nGeneral help regarding Excel for single worksheet functions is available at Super User (http://superuser.com/).",
      "tag_name": "excel"
    },
    {
      "excerpt_last_edit_date": 1621391985,
      "body_last_edit_date": 1638257067,
      "excerpt": "PHP is a widely used, open source, general-purpose, multi-paradigm, dynamically typed and interpreted scripting language originally designed for server-side web development. Use this tag for questions about programming in the PHP language.",
      "tag_name": "php"
    },
    {
      "excerpt_last_edit_date": 1516215242,
      "body_last_edit_date": 1633427147,
      "excerpt": "Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.",
      "tag_name": "sql"

but the order of my tags is C#, SQL, Excel, PHP.

Can I get the items in the order I asked for?

1 Answer 1

1

Can I get the items in the order I asked for?

No, you can't. And I'm pretty sure that is not a bug.

In general, the implementation philosophy of the code and SQL behind the scenes that makes the Stack Exchange sites and the API tick is that when not explicitly needed there is no guaranteed order.

This means that SQL statements often lack an ORDER BY clause. Using this strategy leaves it to SQL Server in which order to return rows and it can do so in the most efficient way.
The main argument for making this implementation choice is to achieve a better timing performance overall for all users.

In your specific scenario, I suspect it would complicate the underlying logic and / or query significantly while the lack of ordering can be trivially fixed by the consumer of the result.

Keeping it simple would benefit all of us.

If you use a language that has associative arrays this easy to solve client-side:

var tags = 'c#;sql;excel;php';
document.getElementById('tags').textContent = tags;

var tagResults = tags.split(';').reduce( (p,c) => { p[c] = {}; return p; }, {});

fetch('https://api.stackexchange.com/2.3/tags/' + encodeURIComponent(tags) + '/wikis?site=stackoverflow')
  .then( (response) => {  return response.json() })
  .then( (json) => {
      json.items.forEach( item => { tagResults[item.tag_name] = item;});
      return JSON.stringify(tagResults, null, 2);
    })
  .then( (text) => { document.getElementById('tagResult').textContent = text; });
<h1>Tags to fetch: <span id='tags'></span></h1>
<pre id='tagResult'>
</pre>

5
  • So you'd rather all your consumers order the data themselves, rather than a simple bit of code on your side?
    – JMP
    Dec 4, 2021 at 13:36
  • 1
    Yes, definitely.
    – rene
    Dec 4, 2021 at 14:50
  • In defence of the question, it would be nice if the endpoint supported sort query parameter just like the other endpoints do (although I know it's wishful thinking). That said, yeah, given the company does not actively develop the API, adding an ability to sort by "order of provided tags" would require a much more substantial use case than a couple of users (@JMP - heck, they haven't added tag wikis/excerpt to suggested edits after 6 to 8 years) Dec 11, 2021 at 19:35
  • @OlegValter; They do use multiple tags in the API quite a lot though. The code only has to be something like tagInfo[0]=getTagInfo('c++'); tagInfo[1]=getTagInfo('php'); which should work asynchronously.
    – JMP
    Dec 12, 2021 at 8:48
  • i.e. wrap each id in a Promise in an array, and then wrap the whole array in a Promise.
    – JMP
    Feb 12 at 23:04

You must log in to answer this question.

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