# How to: Work with subservices

Spark allows users to separate different groups of calculations into subservices. For example, imagine an Excel file that performs addition on one set of values and multiplication on another. Only one set of results is may be needed at a time. With subservices, the request can specify just one of the the operations instead of returning the addition and multiplication results every time.

## Map the subservice

Syntax: `Xinput_<subservice>.<parameter>` and `Xoutput_<subservice>.<parameter>`

1. Follow the instructions to create a name in [How to: Map inputs and outputs](/build-spark-services/map-inputs-and-outputs.md#define-a-named-range-in-excel) for the selected range.
2. When creating the name, use the noted prefix defined in the syntax.

### Example of mapping subservices

![](/files/-MbpBnhEHLywEZB57Idx)

![](/files/-MbpBpXlMPJMEXFZefcg)

In this example, within the same Excel file there are 2 products being priced, `ProductX` and `ProductY`. These 2 products are separated into 2 subservices. Each subservice has 2 `Xinput`s, `Age` and `Sex`. Corresponding outputs need to be mapped for the `ProductX` and `ProductY` subservices.

## Submit API requests for subservices

1. In the [API Tester](/navigation/api-tester.md) [API Tester](/navigation/api-tester.md#adjust-service-parameters), there is a field to select subservices.
   * When a Spark services has no subservices, this field is blank.
   * When a Spark Service has subservices, the field initially contains *Default.*
2. Use the dropdown to select which subservices to include in the API call.
3. Spark filters the inputs and outputs based on the selected subservices.

## Integrating to a subservice

To understand how to call a subservice, use the API Tester "Raw view" to review the parameters.

* The selected subservices are included in the [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request_meta) parameter `service_category`.
* The `Default` subservice mentioned above is denoted as `#Default#`.

Find out more in the *Parameters to control the response outputs* of the [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request_meta).

## Metadata subservice

{% hint style="warning" %}
The static `meatdata` subservice only works for [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md). It will calculate dynamically for [Execute API (v4)](/spark-apis/execute-api/execute-api-v4.md) and [Batch APIs](/spark-apis/batch-apis.md).
{% endhint %}

Syntax: `Xoutput_metadata.<parameter>`

Use the metadata subservice together with the [Metadata API](/spark-apis/metadata-api.md) for static data (in other words, data that doesn't change when other inputs change). This subservice is much faster than using the full [Execute API](/spark-apis/execute-api.md), since it does not perform any calculations.

* The process to assign data to the metadata subservice is the same as in [How to: Map inputs and outputs](/build-spark-services/map-inputs-and-outputs.md#map-a-single-multiple-cell-range-to-an-input-output).
* Spark stores this data separately from the Excel in a JSON file. The treatment of these outputs in the [API Tester](/navigation/api-tester.md) is the same as for other subservices.
  * Similar to [How to: Map inputs and outputs](/build-spark-services/map-inputs-and-outputs.md#set-default-values-for-a-calculation), if the metadata output contains a formula, Spark will evaluate it upon upload and save the value.
  * Any other subservices that depend on the reference will always use this calculated value.
* The metadata subservice can also store and return images, see [Extract images (Ximage)](/build-spark-services/other-mapping-options/extract-images.md#return-an-image-as-a-base64-string).

## Example file

Upload the example service to Spark to practice using subservices. Map the output cells for the two subservice inputs in the file and use the API tester to pick a subservice and control which values are returned. You can also map a range to a metadata output and see this feature in action.

{% file src="/files/IiPb8UFQqOATR1g5TqyX" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherent.global/build-spark-services/subservices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
