> For the complete documentation index, see [llms.txt](https://docs.coherent.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherent.global/assistant/custom-functions/xcall-legacy-functions/callapi.md).

# CALLAPI

This legacy function allows the user to call Spark service API through Coherent Assistant.

{% hint style="warning" %}
This function is deprecated and replaced with [SPARK\_XCALL](/assistant/custom-functions/spark_xcall.md).

The functions [CALLAPI](/assistant/custom-functions/xcall-legacy-functions/callapi.md) and [GETOUTPUT](/assistant/custom-functions/xcall-legacy-functions/getoutput.md) functions work together.
{% endhint %}

Syntax: `CS.SPARK_CALLAPI(xcall_block)`

Call Spark service APIs. Retrieve the output using [GETOUTPUT](/assistant/custom-functions/xcall-legacy-functions/getoutput.md).

| Parameter        | Description                                                                                                                                                  |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `xcall_block` \* | <p>Range address of the <code>Xcall</code> block in upstream service. You can also use a named range for convenience.<br>Example: <code>$A$1:$B$4</code></p> |

## `xcall_block` block

Create a `xcall_block` block in the Excel workbook (upstream service) to make an API call. The `xcall_block` block can be anywhere in your workbook but must be on the same sheet as the `CS.SPARK_CALLAPI` function. The `4 row x 2 column` table must include this information:

<table><thead><tr><th>Key</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>CALLTYPE</code></td><td><code>SparkService</code></td><td><code>SparkService</code></td></tr><tr><td><code>FOLDERNAME</code></td><td>Name of the folder containing downstream service.</td><td><code>myfolder</code></td></tr><tr><td><code>SERVICENAME</code></td><td>Name of downstream service.</td><td><code>myservice</code></td></tr><tr><td><code>REQUESTBODY</code></td><td>Payload for calling downstream service. Must be in JSON format. You can copy the from the downstream service API Tester.</td><td><p></p><pre class="language-json"><code class="lang-json">{
  "request_data": {
    "inputs": {
      "a": 1
    }
  },
  "request_meta": {
  }
}
</code></pre></td></tr></tbody></table>

## Output

The function will return a JSON formatted string with two parts.

* The first, `metadata`, contains information about the call to the downstream service such as `status`, `error_code`, and `response_time`.
* The second, `data`, contains the response body of the downstream service.

### Sample response

```json
{
    "metadata": {
        "name": null,
        "calltype": "SparkService",
        "status": "200",
        "error_code": "",
        "response_time": "225"
    },
    "data": {
        "status": "Success",
        "response_data": {
            "outputs": {
                "OutputField": "OutputValue"
            },
            "warnings": [],
            "errors": [],
            "service_chain": []
        },
        "response_meta": {
            "service_id": "166f5109-b01f-4d14-b10d-49669e3489e0",
            "version_id": "52e710a8-9ca1-4ab2-9366-dc304a9eb670",
            "version": "1.0.0",
            "process_time": 4,
            "call_id": "07ea654c-4136-4075-a195-7eaba15391c4",
            "compiler_type": "Type3",
            "compiler_version": "1.0.0",
            "source_hash": null,
            "engine_id": "F0D5B2B02645AAE15F63BABFBF94FBEF",
            "correlation_id": "",
            "system": "SPARK",
            "request_timestamp": "2022-02-28T16:14:25.148Z"
        },
        "error": null
    }
}
```
