# gRPC Client

> Call gRPC Service method.

Source: https://docs.sommatic.ai/en/nodes/io.grpc/

- Slug: `io.grpc`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Call gRPC Service method.

## Configuration

- `connection_id` (string, required): Credential for the gRPC endpoint. Accepts credentials of type `certificate` (TLS cert + key for mTLS) or `object` (host + .proto path + advanced config).
- `service` (string, required): Service Name
- `method` (string, required): Method Name
- `payload` (object, optional): Request Message

## Output ports

- `out` (default): gRPC Response Message
- `error`: gRPC Error Code

## Input contract

- `connection_id` (string, required)
- `service` (string, required)
- `method` (string, required)
- `payload` (object, optional)

## Output contract

- `response` (object, optional): gRPC Response Message

## In expressions

What a later node can read from this node's output with `$("gRPC Client").item.json.<path>` (write your node's label instead of `gRPC Client`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("gRPC Client").item.json.response` (object) = `{…}`: gRPC Response Message
- `$("gRPC Client").item.json.response.order_id` (string) = `"ord_123"` (Not suggested by the editor)
- `$("gRPC Client").item.json.response.status` (string) = `"CONFIRMED"` (Not suggested by the editor)
- `$("gRPC Client").item.json.response.total_cents` (string) = `"25000"` (Not suggested by the editor)


## How it works

Calls one unary method of a gRPC service described by a `.proto` file available to the orchestrator, using host and proto settings from a credential.

1. Resolves the config. `connection_id`, `service` and `method` fall back to the same keys of the incoming payload.
2. Builds the request message: the configured `payload` when it is a non-empty object; otherwise `payload.payload` of the incoming data, or the whole incoming data.
3. Resolves the credential config: `host` (`host:port`), `protoPath` (a file on the orchestrator file system), optional `packageName` and `secure`.
4. Loads the proto (field names kept as written, longs and enums as strings, defaults filled), finds `packageName` and then `service`, and opens a TLS channel when `secure` is true or a plaintext one otherwise.
5. Calls `method` with the message and, when the secret has `token`, the metadata `Authorization: Bearer <token>`. The reply leaves through `out` as `{ response }`.

## In a workflow

### Node

```json
{
  "node_id": "node-confirm-order",
  "label": "Confirm order",
  "operator_slug": "io.grpc",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "service": "OrderService",
    "method": "ConfirmOrder",
    "payload": {
      "order_id": "{{ $json.order_id }}"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "response": {
      "order_id": "ord_123",
      "status": "CONFIRMED",
      "total_cents": "25000"
    }
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The method returned a reply. `response` is the decoded reply message.

```json
{
  "response": {
    "order_id": "ord_123",
    "status": "CONFIRMED",
    "total_cents": "25000"
  }
}
```

### `error`

The call returned a gRPC status error (data is `{ error, code }` with the numeric gRPC code), or the setup failed (data is `{ error }`).

```json
{
  "error": "14 UNAVAILABLE: No connection established",
  "code": 14
}
```

## Behaviour in the code

- `connection_id`: The credential config must hold `host`, `protoPath`, optional `packageName` and `secure`; only `token` is read from the secret. `certificate` credentials are accepted by the picker, but client certificates are not used: TLS uses the system trust store without a client certificate (no mTLS).
- `payload`: The request message. An empty object counts as not set, and the incoming data is sent instead.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `protoPath missing in connection config` | `error` | The credential config has no `protoPath`. Add the path of a `.proto` file that exists on the orchestrator host. |
| `Package <packageName> not found in proto` | `error` | `packageName` does not match a top-level package of the proto. Only a single-segment name is looked up (`helloworld`, not `acme.orders`). |
| `Service <service> not found` | `error` | `service` is not defined in the selected package. |
| `Method <method> not found` | `error` | `method` is not a method of the service. Use the name as written in the proto. |
| `connection_id is required` | `error` | No credential selected. |

## Notes and limits

- Only unary calls are supported; streaming methods are not handled. No deadline is set on the call, and there are no retries.
- The `.proto` file is read from the orchestrator file system on each run; it is not uploaded with the workflow.
- 64-bit integers and enums arrive as strings in `response`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.grpc",
  "name": "gRPC Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Call gRPC Service method.",
  "capabilities": [
    "grpc",
    "microservices",
    "protobuf"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "gRPC Credential",
        "description": "Credential for the gRPC endpoint. Accepts credentials of type `certificate` (TLS cert + key for mTLS) or `object` (host + .proto path + advanced config).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "certificate",
            "object"
          ],
          "types": [
            "grpc"
          ]
        }
      },
      "service": {
        "type": "string",
        "description": "Service Name"
      },
      "method": {
        "type": "string",
        "description": "Method Name"
      },
      "payload": {
        "type": "object",
        "description": "Request Message"
      }
    },
    "required": [
      "connection_id",
      "service",
      "method"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "service": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "payload": {
        "type": "object"
      }
    },
    "required": [
      "connection_id",
      "service",
      "method"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "response": {
        "type": "object",
        "description": "gRPC Response Message"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Response",
      "description": "gRPC Response Message",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "gRPC Error Code",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "microservices"
  ],
  "tags": [
    "grpc",
    "rpc"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "gRPC Credential",
      "description": "Credential for the gRPC endpoint. Accepts credentials of type `certificate` (TLS cert + key for mTLS) or `object` (host + .proto path + advanced config).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "certificate",
          "object"
        ],
        "types": [
          "grpc"
        ]
      }
    },
    "service": {
      "type": "string",
      "description": "Service Name"
    },
    "method": {
      "type": "string",
      "description": "Method Name"
    },
    "payload": {
      "type": "object",
      "description": "Request Message"
    }
  },
  "required": [
    "connection_id",
    "service",
    "method"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "service": {
      "type": "string"
    },
    "method": {
      "type": "string"
    },
    "payload": {
      "type": "object"
    }
  },
  "required": [
    "connection_id",
    "service",
    "method"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "description": "gRPC Response Message"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Response",
    "description": "gRPC Response Message",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "gRPC Error Code",
    "is_default": false,
    "supports_condition": false
  }
]
```
