Generating search token for /user/search endpoint

Hello!

I have an existing client implementation that uses the /user/search endpoint with a simple request like this:

def searchuser(self, email):
    params = {"email": email, "exact": "true"}
    url = urljoin(self.urlbase, "/user/search/")
    r = self._request("GET", url, params=params)
    return r.json()["users"]

This previously worked for searching users by email. However, it seems the /user/search endpoint no longer behaves this way and now requires a search token.

I figured a bit hacky way to get it from an admin page, like:

        admin_url = urljoin(self.urlbase, "/admin/users/")
        admin_page = self._request("GET", admin_url)
        token_match = re.search(r'data-search-token="([^"]+)"', admin_page.text)
        search_token = token_match.group(1) 

And use that token in the params of “/user/search/” endpoint. But I was wondering if there is a better/intended way of doing this, rather than what I am doing.

Thanks in advance!

Send a GET request to /search/token (authenticated with a personal token as usual).

You need to provide one of these query string args: category_id, event_id, contribution_id, session_id

If you are an admin, then category_id=0 is the easiest one to go for, otherwise you need to use the ID of something which you can actually manage.

1 Like

Yep, user will always be the admin. category_id looks easiest.

Many thanks!