Skip to main content
import { useState } from 'react';
import { useStytchB2BClient } from '@stytch/react/b2b';

export const SearchMembers = () => {
  const stytch = useStytchB2BClient();
  const [emailQuery, setEmailQuery] = useState('');
  const [members, setMembers] = useState([]);

  const handleSearch = async () => {
    const response = await stytch.organizations.members.search({
      query: {
        operator: 'AND',
        operands: [
          {
            filter_name: 'member_email_fuzzy',
            value: emailQuery
          }
        ]
      }
    });
    setMembers(response.members);
  };

  return (
    <div>
      <input
        value={emailQuery}
        onChange={(e) => setEmailQuery(e.target.value)}
        placeholder="Search by email..."
      />
      <button onClick={handleSearch}>Search</button>
      <div>
        {members.map((member) => (
          <div key={member.member_id}>
            {member.name} - {member.email_address}
          </div>
        ))}
      </div>
    </div>
  );
};
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "results_metadata": {
    "next_cursor": null,
    "total": 5
  },
  "members": [
    { ... },
  ],
  "organizations": {
    "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931": {
      ...
    }
  }
}
organizations.members.search wraps the search members endpoint. It can be used to search for within the logged-in Member’s . Submitting an empty query returns all non-deleted Members within the logged-in Member’s Organization.
RBAC Enforced MethodThis method requires a valid Session for a member with permission to perform the Action on the Resource.Before using this method, enable Member actions & organization modifications in the Frontend SDK page. To learn more, see our RBAC guide.

Parameters

cursor
string
The cursor field allows you to paginate through your results. Each result array is limited to 1000 results. If your query returns more than 1000 results, you will need to paginate the responses using the cursor.If you receive a response that includes a non-null next_cursor in the results_metadata object, repeat the search call with the next_cursor value set to the cursor field to retrieve the next page of results. Continue to make search calls until the next_cursor in the response is null.
limit
number
default:100
The number of search results to return per page. The default limit is 100.A maximum of 1000 results can be returned by a single search request. If the total size of your result set is greater than one page size, you must paginate the response. See the cursor field.
query
string
The optional query object contains the operator, i.e. AND or OR, and the operands that will filter your results. Only an operator is required.If you include no operands, no filtering will be applied. If you include no query object, it will return all Members with no filtering applied.

Response

results_metadata
object
Metadata relevant to your specific query.
members
object[]
An array of Member objects that match your search query.
organizations
Record<string, Organization>
A map from organization_id to the Organization object. It will only contain Organizations that contain at least one member returned by the query.
request_id
string
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
status_code
number
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.