# Response Format

### Rule Response Content Type

By default, when triggering a rule—whether it's a **SimpleRule**, **DecisionTable**, or **Ruleset**—via API, the response is returned in **JSON** format. This is the standard for the **Test Result** tabs inside the Nected platform, where rule responses are displayed as formatted JSON for easy inspection and debugging.

However, when rules are called via API (either from an external system or another Nected rule/workflow), the **response format** and **input format** can both be fully controlled using standard HTTP headers:

#### **Set Response Format Using `Accept` Header**

To receive the rule response in a format other than JSON, set the `Accept` header in your API call accordingly:

| Format           | Accept Header                       |
| ---------------- | ----------------------------------- |
| JSON             | `application/json` *(default)*      |
| XML              | `application/xml`                   |
| HTML             | `text/html`                         |
| Text             | `text/plain`                        |
| FORM             | `multipart/form-data`               |
| FORM URL Encoded | `application/x-www-form-urlencoded` |

**Example for XML Response:**

```bash
curl -X POST "<https://nected-59.nected.io/nected/rule/><rule_id>" \\
  -H "Content-Type: application/json" \\
  -H "Accept: application/xml" \\
  -d '{
    "environment": "production",
    "params": {
      "user_id": 12345
    },
    "version": "1.0"
}'

```

This will return the same rule response structure in **XML format**, for example:

```xml
<response>
  <code>success</code>
  <message>Success</message>
  <data>
    <executionId>ruleLive:...</executionId>
    <executionTime>42ms</executionTime>
    <output>
      <score>92</score>
      <recommendation>accept</recommendation>
    </output>
    <ruleId>abc-123</ruleId>
  </data>
</response>

```

#### **Set Input Format Using `Content-Type` Header**

Similarly, rule input can be submitted in alternative formats (e.g., XML or form-encoded), as long as the correct `Content-Type` header is set in the request. Internally, Nected will parse the request based on this type and evaluate it as intended.

| Format           | Accept Header                       |
| ---------------- | ----------------------------------- |
| JSON             | `application/json` *(default)*      |
| XML              | `application/xml`                   |
| HTML             | `text/html`                         |
| Text             | `text/plain`                        |
| FORM             | `multipart/form-data`               |
| FORM URL Encoded | `application/x-www-form-urlencoded` |

**Example for XML Input Payload:**

```xml
<root>
  <environment>production</environment>
  <params>
    <user_id>12345</user_id>
  </params>
  <version>1.0</version>
</root>

```

Sent via:

```bash
curl -X POST "<https://nected-59.nected.io/nected/rule/><rule_id>" \\
  -H "Content-Type: application/xml" \\
  -H "Accept: application/xml" \\
--data ' <root>
     <environment>staging</environment> // or production
     <params>
     ...// all params
     </params>
 </root>'

```

Nected will parse this XML input, process the rule logic, and return the response in the requested format (e.g., XML).

\<aside> ⚙

Even though you can set custom content types for **input** and **output** in live API calls, the **Test Result tabs** in Nected (for rules, workflows, or connectors) **always render results in JSON** for consistent visual formatting. However, this does not affect the actual runtime behavior of your API calls.

\</aside>

Use the `Accept` and `Content-Type` headers to handle XML, plain text, or other formats externally when integrating with legacy systems, ERP platforms, or custom frontends.

***

### **Workflow Response Content Type**

By default, when invoking a workflow via API, Nected returns the output in **JSON format**. This format is displayed in the **Test Result** tab within the platform to ensure consistent and clear output visualization during testing.

However, you can customize both the **response format** and **input format** when executing a workflow externally (from another system or service) by specifying standard HTTP headers.

#### **Set Workflow Response Format Using `Accept` Header**

To receive the workflow execution result in a specific format, you can set the `Accept` header in your API request. This allows seamless integration with systems that require XML, plain text, or other response formats.

| Format           | Accept Header                       |
| ---------------- | ----------------------------------- |
| JSON             | `application/json` *(default)*      |
| XML              | `application/xml`                   |
| HTML             | `text/html`                         |
| Text             | `text/plain`                        |
| FORM             | `multipart/form-data`               |
| FORM URL Encoded | `application/x-www-form-urlencoded` |

**Example API Call for XML Response:**

```bash
curl -X POST "<https://nected-59.nected.io/nected/workflow/><workflow_id>" \\
  -H "Content-Type: application/json" \\
  -H "Accept: application/xml" \\
  -d '{
    "environment": "production",
    "params": {
      "cart": {
        "userId": 101,
        "email": "alice@example.com",
        "cart_list": [...]
      }
    },
    "version": "1.0"
}'

```

**Sample XML Response:**

```xml
<response>
  <code>success</code>
  <message>Success</message>
  <data>
    <executionId>workflowLive:60:workflow_id:1.0:uuid</executionId>
    <executionTime>85ms</executionTime>
    <output>
      <recommendation>bundle_offer_2</recommendation>
      <cart_score>92</cart_score>
    </output>
    <workflowId>workflow_id</workflowId>
    <version>1.0</version>
    <name>Cart Analysis</name>
  </data>
</response>

```

#### **Set Workflow Input Format Using `Content-Type` Header**

Just like with rule execution, you can post input in formats other than JSON, such as XML or form-encoded strings, by setting the `Content-Type` header accordingly.

| Format           | Accept Header                       |
| ---------------- | ----------------------------------- |
| JSON             | `application/json` *(default)*      |
| XML              | `application/xml`                   |
| HTML             | `text/html`                         |
| Text             | `text/plain`                        |
| FORM             | `multipart/form-data`               |
| FORM URL Encoded | `application/x-www-form-urlencoded` |

**Example XML Input:**

```xml
<root>
  <environment>production</environment>
  <params>
    <cart>
      <userId>101</userId>
      <email>alice@example.com</email>
      <cart_list>...</cart_list>
    </cart>
  </params>
  <version>1.0</version>
</root>

```

Sent via:

```bash
curl --location '<https://nected-59.nected.io/nected/workflow/c2971bbf-18a1-4a87-b0fe-d2c426d063d8>' \\
--header 'Accept: application/x-www-form-urlencoded' \\
--header 'Content-Type: application/xml' \\
--data ' <root>
     <environment>staging</environment> // or production
     <params>
     ...// all params
     </params>
 </root>'

```

Use `Accept` and `Content-Type` headers as needed to ensure your workflows can interact seamlessly with systems requiring specific input or response formats, such as enterprise backends, legacy software, or third-party API consumers.
