# `Kinde.ManagementAPI`
[🔗](https://github.com/starfish-codes/elixir-kinde/blob/v2.1.0/lib/kinde/management_api.ex#L1)

Client for the [Kinde Management API](https://docs.kinde.com/kinde-apis/management/).

Starts as a GenServer under the application supervisor and automatically
obtains and renews an access token using the client credentials flow.

## Configuration

    config :kinde, :management_api,
      client_id: "management_client_id",
      client_secret: "management_client_secret",
      business_domain: "https://yourapp.kinde.com"  # defaults to :domain

If `:business_domain` is not set, the top-level `:domain` config value is used.

The server returns `:ignore` on startup when required keys are missing, so the
application can still boot without Management API credentials.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `delete_mfa`

```elixir
@spec delete_mfa(String.t(), GenServer.server()) :: :ok | {:error, term()}
```

Deletes all MFA settings for a user.

Returns `:ok` on success, `{:error, %APIError{}}` on API errors,
or `{:error, %NoAccessTokenError{}}` if the access token hasn't been obtained yet.

## Examples

    iex> Kinde.ManagementAPI.delete_mfa("kp_abc123def456")
    :ok

# `get_user`

```elixir
@spec get_user(String.t(), GenServer.server()) :: {:ok, map()} | {:error, term()}
```

Fetches a user by their Kinde ID.

Returns `{:ok, user_map}` on success, `{:error, %APIError{}}` on API errors,
or `{:error, %NoAccessTokenError{}}` if the access token hasn't been obtained yet.

## Examples

    iex> Kinde.ManagementAPI.get_user("kp_abc123def456")
    {:ok, %{"first_name" => "Mary", "last_name" => "Doe", ...}}

# `list_users`

```elixir
@spec list_users(GenServer.server()) :: {:ok, [map()]} | {:error, term()}
```

Fetches all users, handling pagination automatically.

Returns `{:ok, [user_map]}` with a flat list of all users across all pages.

## Examples

    iex> Kinde.ManagementAPI.list_users()
    {:ok, [%{"first_name" => "John", ...}, %{"first_name" => "Jane", ...}]}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
