No internet connection
  1. Home
  2. Issues

Getting "No xsrf token" error when trying to contact search endpoint

By Christian Scheuer @chrscheuer
    2021-08-19 12:35:44.727Z

    I'm trying to implement forum search into our macOS app. We need to call the search endpoint from either Javascript running locally in Electron (so there's no user signed in) or via C#.
    Both methods complain that there's no XSRF token which I can understand since we're just making that single request.

    System.Exception: Error decoding JSON from endpoint 403 Forbidden
    No xsrf token [TyE0XSRFTKN]

    How can we go about making this work?

    Solved in post #10, click to view
    • 15 replies
    1. Temp workaround: You can go to in a browser, open Dev Tools, go to the Application tab, and copy the XSRF-TOKEN cookie value. Then, include it in the request to /-/v0/search:

      Won't work, currently — no XSRF token:

      $ curl -H 'Content-Type: application/json' -X POST '' -d '{
          "searchQuery": { "freetext": "xsrf" },
          "pretty": true
      403 Forbidden
      No xsrf token [TyE0XSRFTKN]

      But this works: (with an XSRF token for Ty .io from my browser (which I've since deleted))

      $ curl -H 'X-XSRF-TOKEN: 16293.......ZkG' -H 'Content-Type: application/json' -X POST '' -d '{
          "searchQuery": { "freetext": "xsrf" },
          "pretty": true
      ## the response:
        "origin" : "",
        "thingsFound" : [ {
          "pageId" : "594",
          "title" : "Getting \"No xsrf token\" error when trying to contact search endpoint",
          "urlPath" : "/-594/getting-no-xsrf-token-error-when-trying-to-contact-search-endpoint",

      Since there's no session cookie in these API requests, the XSRF check Talkyard does, seems unnecessary. Maybe the XSRF check could be skipped in these cases

      1. In reply tochrscheuer:

        I'll make a change so Talkyard won't require any XSRF token, when there's no session. This'll be included in the upcoming release ... on Sunday? or Monday?

        We need to call the search endpoint

        (I suppose this is for searching among the publicly visible topics. Since there're no credentials in these requests, access restricted topics wouldn't be found.)

        1. CChristian Scheuer @chrscheuer
            2021-08-20 13:04:21.179Z

            Yes exactly. Just public topics are expected to be returned :)

            Perfect that you can get this in the next release - really appreciate it!

            1. CChristian Scheuer @chrscheuer
                2021-08-23 09:46:54.306Z

                Hi @KajMagnus - please lmk when this is live :)

                1. Yes, just upgraded this server Ty .io, probably Prod tomorrow.

                  1. B.t.w., now this works, here: (no X-XSRF-TOKEN header needed)

                    curl -X POST -H 'Content-Type: application/json' -d '{
                      "searchQuery": { "freetext": "lmk" },
                      "pretty": true
                    1. CChristian Scheuer @chrscheuer
                        2021-08-23 16:57:41.672Z

                        Confirmed working here (on! Great work, can't wait for it to be in prod.

                        1. Server upgraded, now this works:

                          curl -X POST -H 'Content-Type: application/json' -d '{
                            "searchQuery": { "freetext": "IFTTT" },
                            "pretty": true
                          Reply1 LikeSolution
                          1. CChristian Scheuer @chrscheuer
                              2021-08-25 19:48:51.978Z

                              Awesome! It works great :)

                              I don't remember - is there a way to limit the search to a specific category or set of categories?

                              1. Yes (sorry I forgot to get back about that), by including category:category-slug in the search query, e.g. search for: "trees categories:ideas". In cURL:

                                curl -X POST -H 'Content-Type: application/json' -d '{
                                  "searchQuery": { "freetext": "lmk categories:issues" },
                                  "pretty": true

                                Search in many categories: Add more slugs, comma separated, no space between, e.g.: category:issues,support

                                1. @chrscheuer: Maybe a problem: Currently, to search in all SoundFlow packages sub categories in Soundflow, you'd need to list each one of the sub categories, in the category:... list. But then the search query would get too long, and rejected.

                                  You have in mind to search in all sub categories? (Or only some base categories?)

                                  (Anyway, this'll be a problem eventually for someone, so should get fixed)

                                  1. CChristian Scheuer @chrscheuer
                                      2021-08-27 20:32:51.019Z

                                      This won't be a problem, I think :) We would either want to search in a specific category or across the whole site.

                                      1. CChristian Scheuer @chrscheuer
                                          2021-08-27 20:34:07.775Z

                                          Specifically, we'd by default want to search in "How to" for our in-app search. By doing this we'll automatically exclude the "Support" category for example as that brings too much noise.
                                          For package specific things it could then additionally (or exclusively) search in the category for that specific package. So yea, at most we'd search in 2-3 categories at once in total, but most of the time either 1 or all.

                                      2. In reply toKajMagnus:
                                        CChristian Scheuer @chrscheuer
                                          2021-08-27 20:32:08.605Z

                                          Oops just replied in the other thread. Wasn't aware you could do this with searching in categories. Awesome!

                        2. C
                          In reply tochrscheuer:
                          Christian Scheuer @chrscheuer
                            2021-10-18 14:58:08.276Z

                            We've got forum search working in our app now. Sooo nice!

                            1. Progress
                              with handling this problem
                            2. @KajMagnus marked this topic as Started 2021-08-20 05:37:50.732Z.