> ## Documentation Index
> Fetch the complete documentation index at: https://docs.modelence.com/llms.txt
> Use this file to discover all available pages before exploring further.

# callMethod

[API Reference](/api-reference/modelence/client/functions/../../../index) / [modelence](/api-reference/modelence/client/functions/../../index) / [client](/api-reference/modelence/client/functions/../index) / callMethod

> **callMethod**\<`T`>(`methodName`, `args?`, `options?`): `Promise`\<`T`>

Defined in: [packages/modelence/src/client/method.ts:103](https://github.com/modelence/modelence/blob/f614ecc6811cdda9670d612872c8ff49a49c5e28/packages/modelence/src/client/method.ts#L103)

Calls a server-side method (query or mutation) defined on a Modelence module.

Both `args` and `options` are optional. Use the type parameter `T` to type the return value.

## Example

```typescript theme={null}
import { callMethod } from 'modelence/client';

// No arguments
const todos = await callMethod<Todo[]>('todo.getAll');

// With arguments
const todo = await callMethod<Todo>('todo.getOne', { id: '123' });

// With a custom error handler
const created = await callMethod<Todo>(
  'todo.create',
  { title: 'Buy groceries' },
  { errorHandler: (error, methodName) => console.error(methodName, error) }
);
```

## Type Parameters

| Type Parameter | Default type |
| -------------- | ------------ |
| `T`            | `unknown`    |

## Parameters

| Parameter    | Type                                                                                               | Description                                                                                                                            |
| ------------ | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `methodName` | `string`                                                                                           | Fully qualified method name, e.g. `'todo.getAll'`.                                                                                     |
| `args?`      | [`MethodArgs`](/api-reference/modelence/client/functions/../type-aliases/MethodArgs)               | Arguments passed to the server-side method. Defaults to `{}`.                                                                          |
| `options?`   | [`CallMethodOptions`](/api-reference/modelence/client/functions/../type-aliases/CallMethodOptions) | Call-site options such as a custom [CallMethodOptions.errorHandler](../type-aliases/CallMethodOptions#errorhandler). Defaults to `{}`. |

## Returns

`Promise`\<`T`>

A promise that resolves to the method's return value.
