# Implement or use DoCommand

The `DoCommand` method is a flexible wrapper that you can use to send commands that have no corresponding built-in API method. `DoCommand` is part of every [component](https://docs.viam.com/reference/apis/#component-apis) and [service API](https://docs.viam.com/reference/apis/#service-apis), though most models do not implement it.

In the majority of cases, you should use a more specific method for your component or service. As the developer of a resource, you can implement `DoCommand` in your module if you need to add custom commands to your resource.

As the user of a resource, you can only call `DoCommand` if it is implemented in the model you are using. Refer to the model’s documentation to see whether `DoCommand` is implemented and how to use it.

## Implement DoCommand in your component or service

`DoCommand` takes a map of key-value pairs as input. The contents of the map are entirely up to the developer of the resource.

`DoCommand` also returns a map of key-value pairs, but many implementations return an empty map, or a map that confirms that the command was received.

There are many ways to implement `DoCommand` in your module, with the following example being just one. See [More examples](https://docs.viam.com/reference/sdks/docommand/#more-examples) for more.

### Example implementation

Imagine you have a robotic vacuum cleaner that has a docking sequence and can clean specific areas such as the kitchen and the living room.

You could [write a module](https://docs.viam.com/build-modules/write-a-driver-module/) that implements the [base API](https://docs.viam.com/reference/apis/components/base/). The base API includes methods like `MoveStraight` to drive the vacuum cleaner around, and like all resource APIs, it includes a `DoCommand` method. In addition to the standard base methods, you could implement `DoCommand` to trigger the docking and cleaning sequences:

- [Python](https://docs.viam.com/reference/sdks/docommand/#tabset-referencesdksdocommand-1-0)
- [Go](https://docs.viam.com/reference/sdks/docommand/#tabset-referencesdksdocommand-1-1)

```python

```

```go

```

## Use DoCommand in SDK code

Continuing with the vacuum cleaner example, you could use `DoCommand` in your control code as follows:

- [Python](https://docs.viam.com/reference/sdks/docommand/#tabset-referencesdksdocommand-2-0)
- [Go](https://docs.viam.com/reference/sdks/docommand/#tabset-referencesdksdocommand-2-1)

```python

```

```go

```

## Use DoCommand in the web UI

You can use `DoCommand` in the web UI:

1. Navigate to your machine’s **CONTROL** tab.
2. Find your resource and expand the **DO COMMAND** section.
3. Enter a key and value in the text box using JSON syntax, for example

```json

```

4. Click **Execute**.

## More examples

For an example that implements `DoCommand` in a generic API Python module, see [Add control logic to your module](https://docs.viam.com/build-modules/write-a-logic-module/#5-implement-docommand).

For additional examples, look at the GitHub repositories of [registry](https://app.viam.com/registry), especially modules that use the generic API. Essentially all generic models implement `DoCommand` (since it is the only method of the generic API), and various other models implement it as well.

\`DoCommand\` is styled as \`do_command\` in Python.
