# Invoke operator API service

Call the published and enabled operator API service. The fields of `payload` must conform to the input definition of the service; first [View Service Configuration](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/operator-api-services/get-operator-api-service.html.md) confirms that the service can be called and obtains the input definition.

```text
POST $CLOUDSIGMA_API_BASE/workflow/v2/workitems/catalog/$NODE_ID/api-service/invoke
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [View Service Configuration](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/operator-api-services/get-operator-api-service.html.md), confirm that the service is enabled, and obtain the operator ID, version and service name of the service to be called.

## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>node_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The ID of the operator to be called.</dd></div>
  <div class="mo-api-field"><dt><code>service_name</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>Service name, using data.service.service_name from the service configuration response.</dd></div>
  <div class="mo-api-field"><dt><code>type</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>Fixed to operator.</dd></div>
  <div class="mo-api-field"><dt><code>version</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The published operator version.</dd></div>
  <div class="mo-api-field"><dt><code>payload</code><span class="mo-api-field__type">object</span></dt><dd>the input data of the service; fields and types are subject to data.service.input_schema.</dd></div>
</dl>
:::
:::{div} mo-api-split-aside

<p class="mo-api-example-label">Request example</p>
```bash
curl -X POST "$CLOUDSIGMA_API_BASE/workflow/v2/workitems/catalog/$NODE_ID/api-service/invoke" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"service_name\": \"$SERVICE_NAME\",
    \"type\": \"operator\",
    \"version\": \"$VERSION\",
    \"payload\": {
      \"sql\": \"SELECT now()\"
    }
  }"
```

:::
::::

## Successful response

`data.result` returns the status and operator output of this call. `result` is returned as a JSON format string; the operator output is read after parsing the string. When `error` appears in the response, handle it as an error message.


The response fields are as follows.

::::{div} mo-api-split
:::{div} mo-api-split-main

<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>OK on success.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>OK on success.</dd></div>
  <div class="mo-api-field"><dt><code>data.result.case_id</code><span class="mo-api-field__type">string</span></dt><dd>ID of this call; can be used to correlate this result when the response is provided.</dd></div>
  <div class="mo-api-field"><dt><code>data.result.status</code><span class="mo-api-field__type">string</span></dt><dd>The status returned by the service; occurs when the response is provided.</dd></div>
  <div class="mo-api-field"><dt><code>data.result.result</code><span class="mo-api-field__type">string</span></dt><dd>JSON format string returned by the service; the parsed structure is determined by the operator.</dd></div>
  <div class="mo-api-field"><dt><code>data.result.error</code><span class="mo-api-field__type">string</span></dt><dd>Error message returned by the service; appears when there is an error.</dd></div>
</dl>
:::
:::{div} mo-api-split-aside

<p class="mo-api-example-label">Successful response example</p>
```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "result": {
      "case_id": "case_01JEX4A1M2",
      "status": "COMPLETED",
      "result": "{\"count\":9}"
    }
  }
}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
:::
:::{div} mo-api-split-aside

<p class="mo-api-example-label">Error response example</p>
```json
{
  "code": "api_service_unavailable",
  "msg": "服务暂不可用",
  "data": null
}
```

:::
::::

## Follow-up operations

After the call is completed, when you need to check the configuration [View operator API service configuration](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/operator-api-services/get-operator-api-service.html.md).
