Search API doesn't work

I am trying to use the Discourse API for a discord bot. I want to pass a search query via my bot and return the results back to discord after utilizing the Discourse API.

The problem is I can’t get the API to work. It just returns a HTML snippet. Here is the CURL request -

curl --location --request GET 'https://forum.andronix.app/search/query?term=Modded%20OS' \
--header 'Api-Key: xxxx2901589946b34f0e81bfc39xxx633deef202b6f004af878fa62xxxxxxxxx' \
--header 'Api-Username: xxxx' 

[The API key and username are correct because they do work for other things].

Here’s the response I get

<!DOCTYPE html>
<html lang="en-US" class="desktop-view not-mobile-device text-size-normal">

<head>
    <meta charset="utf-8">
    <title>Andronix Community</title>
    <meta name="description" content="A place for everything Linux and Andronix">
    <meta name="discourse_theme_ids" content="3">
    <meta name="discourse_current_homepage" content="categories">
    <meta name="generator" content="Discourse 2.5.0.beta3 - https://github.com/discourse/discourse version 5285cbee62ad7b0cee5b3bf0b6449174fb4f4491">
    <link rel="icon" type="image/png" href="https://forum.andronix.app/uploads/default/optimized/1X/3f26e0ac92e114364358d8cfce8c5734ddacf980_2_32x32.png">
    <link rel="apple-touch-icon" type="image/png" href="https://forum.andronix.app/uploads/default/optimized/1X/3f26e0ac92e114364358d8cfce8c5734ddacf980_2_180x180.png">
    <meta name="theme-color" content="#36393e">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">

    <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "WebSite",
            "url": "https://forum.andronix.app",
            "potentialAction": {
                "@type": "SearchAction",
                "target": "https://forum.andronix.app/search?q={search_term_string}",
                "query-input": "required name=search_term_string"
            }
        }
    </script>
    <link rel="search" type="application/opensearchdescription+xml" href="https://forum.andronix.app/opensearch.xml" title="Andronix Community Search">

    <meta name="csrf-param" content="authenticity_token" />
    <meta name="csrf-token" content="3uVup/2b5g9JbWa3bJN0KA8RxeGi64VUXPBO6I58jsvja3QBTtPDeJtvyjlqnL4bSVQ77VuGmc665ukh7ir6aQ==" />

    <meta name="fragment" content="!">


    <link rel="preload" href="/assets/browser-update-331af91e0f999788d03c2128d366d5d0df480718b9e80914bfb0505cbb97af13.js" as="script">
    <script src="/assets/browser-update-331af91e0f999788d03c2128d366d5d0df480718b9e80914bfb0505cbb97af13.js"></script>




</body>

</html>

I have made the response shorter so it doesn’t look like spam

Would be grateful if anyone can point out what I am doing wrong. Thank you!

1 Like

Try using .json at the end:

GET 'https://forum.andronix.app/search/query.json?term=Modded

(or you can use the Accept header to request JSON formatting)

5 Likes