# Generic service API

The generic service API allows you to give commands to your [generic services](https://docs.viam.com/reference/services/generic/) for running model-specific commands using [`DoCommand`](https://docs.viam.com/reference/apis/services/generic/#docommand).

The generic service supports the following methods:

| Method Name | Description |
| --- | --- |
| [`DoCommand`](https://docs.viam.com/reference/apis/services/generic/#docommand) | Execute model-specific commands. |
| [`GetResourceName`](https://docs.viam.com/reference/apis/services/generic/#getresourcename) | Get the `ResourceName` for this instance of the generic service. |
| [`Close`](https://docs.viam.com/reference/apis/services/generic/#close) | Safely shut down the resource and prevent further use. |

## API

### DoCommand

Execute model-specific commands. If you are implementing your own generic service and want to add features that have no corresponding built-in API method, you can implement them with [`DoCommand`](https://docs.viam.com/reference/sdks/docommand/).

- [Python](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-1-0)
- [Go](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-1-1)
- [TypeScript](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-1-2)
- [Flutter](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-1-3)

**Parameters:**

- `command` (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), ValueTypes]) (required): The command to execute.
- `timeout` ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

**Returns:**

- (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), Any]): : Result of the executed command.

**Example:**

```python

```

**For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/services/generic/client/index.html#viam.services.generic.client.GenericClient.do_command).**

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
- `cmd` [(map[string]interface{})](https://go.dev/blog/maps): The command to execute.

**Returns:**

- [(map[string]interface{})](https://pkg.go.dev/builtin#string): The command response.
- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

**Example:**

```go

```

**For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).**

**Parameters:**

- `command` ( [Struct](https://ts.viam.dev/classes/Struct.html)) (required): The command to execute. Accepts either a [Struct](https://ts.viam.dev/classes/Struct.html) or a plain object, which will be converted automatically.
- `callOptions` (CallOptions) (optional)

**Returns:**

- (Promise< [JsonValue](https://ts.viam.dev/types/JsonValue.html) >)

**Example:**

```ts

```

**For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/GenericServiceClient.html#docommand).**

**Parameters:**

- `command` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html) < [String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic> (required)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html) < [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html) < [String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic>>

**Example:**

```dart

```

**For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/GenericServiceClient/doCommand.html).**

### GetResourceName

Get the `ResourceName` for this instance of the generic service.

- [Python](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-2-0)
- [Go](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-2-1)
- [TypeScript](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-2-2)
- [Flutter](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-2-3)

**Parameters:**

- `name` ( [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)) (required): The name of the Resource.

**Returns:**

- ( [viam.proto.common.ResourceName](https://python.viam.dev/autoapi/viam/proto/common/index.html#viam.proto.common.ResourceName)): : The ResourceName of this Resource.

**Example:**

```python

```

**For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/services/generic/client/index.html#viam.services.generic.client.GenericClient.get_resource_name).**

**Parameters:**

- None.

**Returns:**

- [(Name)](https://pkg.go.dev/go.viam.com/rdk@v0.89.0/resource#Name)

**Example:**

```go

```

**For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).**

**Parameters:**

- None.

**Returns:**

- (string): The name of the resource.

**Example:**

```ts

```

**For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/GenericServiceClient.html#name).**

**Parameters:**

- `name` [String](https://api.flutter.dev/flutter/dart-core/String-class.html) (required)

**Returns:**

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/GenericServiceClient/getResourceName.html).**

### Close

Safely shut down the resource and prevent further use.

- [Python](https://docs.viam.com/reference/apis/services/generic/#tabset-referenceapisservicesgeneric-3-0)

**Parameters:**

- None.

**Returns:**

- None.

**Example:**

```python

```

**For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/services/generic/client/index.html#viam.services.generic.client.GenericClient.close).**
