> For the complete documentation index, see [llms.txt](https://docs.enlyze.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enlyze.com/en/integrations/sap/sap-integration-suite-open-connectors-setup-and-testing.md).

# SAP Integration Suite - Open Connectors Setup & Testing

Build and test a **Custom** connector in **SAP Integration Suite → Open Connectors** for the ENLYZE REST API, using an **API key** and a **PreRequest Hook** to inject the upstream `Authorization: Bearer <api-key>` header. Then verify calls in **API Docs** and (optionally) wire the instance into a Cloud Integration iFlow.

### Architecture in 90 seconds

Open Connectors introduces **two authentication layers** you’ll see in UI and cURL:

1. **SAP Open Connectors auth (platform)** — the header shown in **API Docs** like `Authorization: User <…>, Organization <…>, Element <…>`. This authenticates **you** to **Open Connectors**.
2. **Vendor (ENLYZE) auth** — the header **we** add in a **PreRequest Hook**: `Authorization: Bearer <ENLYZE_API_KEY>`.

> Keep them separate: **never paste the Bearer token** into the API Docs Authorization field. That field is for **Open Connectors**. The hook takes care of the ENLYZE header.

### Prerequisites

* An ENLYZE **API key** for the target tenant. Learn how to create one under [Manage API keys](/en/administration/api-keys.md). For production integrations, an Organization API Key is recommended.
* Access to **SAP Integration Suite → Open Connectors** with Connector Builder permissions.

  The [Set Up Integration Suite Trial](https://developers.sap.com/tutorials/cp-starter-isuite-onboard-subscribe.html) is a good tutorial on how to get started with the SAP Integration Suite. Make sure, that you have the right capabiliteis activated in Integration Suite. You need:

  * **Build Integration Scenarios**
  * **Manage APIs**
  * **Extend Non-SAP Connectivity**

  With the **Extend Non-SAP Connectivity** you can create new connectors.<br>

  <figure><img src="/files/Xwbp7TNMJRVkBF37GcuZ" alt=""><figcaption></figcaption></figure>

### Step 1: Import the ENLYZE OpenAPI

1. In **Open Connectors → Connectors** click **Build New Connector**<br>

   <figure><img src="/files/pg0nR1s74mGPhILI04vy" alt=""><figcaption></figcaption></figure>

   \
   Use the **Import** option to create your connector:<br>

   <figure><img src="/files/4u5rhlUCloxiYjeeCPu5" alt=""><figcaption></figcaption></figure>
2. Choose **Swagger** and use the Open API specification to import the configuration: <https://app.enlyze.com/api/v2/openapi.json><br>

   <figure><img src="/files/j3p93MfEqIQ7Rr9EyxpZ" alt=""><figcaption></figcaption></figure>

   \
   Click **Continue Import**.
3. Select the resources you need. Recommended baseline:

   * **GET** `/v2/machines`, `/v2/sites`, `/v2/variables`, `/v2/production-runs`, `/v2/downtimes`, `/v2/products`, `/v2/data-sources`
   * **POST** `/v2/timeseries` (read time series) and **POST** `/v2/machines/{uuid}/productivity-metrics` if required

   <figure><img src="/files/ursgxIz7nERTAeHQHH7V" alt=""><figcaption></figcaption></figure>

> The **Element Key** must be unique in your tenant.

### Step 2: Properties

After the resources are imported, you need to configure the authentication mechanism. We will use a custom authentication where the token is provided at the beginning of the connector setup and is passed to each request via a PreRequest hook.

In **Setup → Properties**:

* **Base URL**: `https://app.enlyze.com/api/`
* **Pagination Type**: `cursor`
* **Accept/Content-Type**: `application/json`
* **Authentication type**: `custom`

<figure><img src="/files/CaT5hEsWsu6i5bpJyTnr" alt=""><figcaption></figcaption></figure>

### Step 3: Configuration (store the token)

In **Setup → Configurations** add:

* **Name**: `API Token`
* **Key**: `api.token` (auto)
* **Type**: `text 128`
* **Required**: **ON**
* **Description**: `ENLYZE API Token` (or a more detailed description)

> We won’t add a global **Authorization** parameter. The hook will inject the upstream header on every call.

<figure><img src="/files/16oaMPWXXT4X0rFaILGd" alt=""><figcaption></figcaption></figure>

### Step 4: PreRequest Hook (inject Bearer)

In **Setup → Hooks → PreRequest Hook**, add:

```javascript
let token = configuration['api.token'];
request_vendor_headers.Authorization = `Bearer ${token}`;
done({"request_vendor_headers":request_vendor_headers,      
      "contintue":true});
```

**Why this works**

* `configuration['api.token']` reads your instance token.
* `request_vendor_headers` targets the **provider-facing** headers (sent to ENLYZE).
* Returning `{ request_vendor_headers }` makes the change effective for the outbound request.

> This will add the {“Authorization”:”Bearer XXXXX”} object to all subsequent calls.

Click **Save**.

<figure><img src="/files/0chmeghLBHD5SjKsPISm" alt=""><figcaption></figcaption></figure>

### Step 5: Test the Connector - Create an Instance

From **Resources** (or **Instances**) click **Authenticate instance**:

<figure><img src="/files/yjWHsq4evV4A7TwTfTXg" alt=""><figcaption></figcaption></figure>

* **Name**: free text (e.g., `Test Instance`)
* **API Token**: **paste the raw token only** (no `Bearer` prefix)

Instance configuration screen:

<figure><img src="/files/pfWsrjOR8JkLMqsCrZTI" alt=""><figcaption></figcaption></figure>

Create the instance.

### Step 6: Test the Connector - via API docs

Open your **instance → API Docs** and pick a simple endpoint, e.g. **GET `/v2/machines`**.

1. Leave the **Authorization** field as the prefilled **Open Connectors** value (User/Organization/Element).
2. Click **Execute**.
3. You should see `200` with JSON. The generated cURL uses a path like:

```shell
https://api.openconnectors.<region>.ondemand.com/elements/api-v2/v2/machines
# Header sent to OC (platform auth):
-H "Authorization: User <…>, Organization <…>, Element <…>"
```

Open Connectors forwards our hook-injected upstream header to ENLYZE:

`Authorization: Bearer <your ENLYZE API key>`

> **Tip**: Use `/v2/sites` or `/v2/machines` for first tests. For time-bounded resources, pass realistic `start`/`end` or `cursor` params.

Test an endpoint:

<figure><img src="/files/gTCTEnYn2SJu5GWKbuJO" alt=""><figcaption></figcaption></figure>

Successful response:

<figure><img src="/files/IVCLTw3U7qzGX1qfHj6P" alt=""><figcaption></figcaption></figure>

### Troubleshooting

#### 401 "User is not authorized" immediately in API Docs

* You’re not authenticating to **Open Connectors**: ensure the API Docs **Authorization** field shows `User…, Organization…, Element…` (it’s usually prefilled). Don’t overwrite it with a Bearer token.

#### 401 from ENLYZE (vendor)

* The upstream header wasn’t added. Recheck the **PreRequest Hook**, save, and **recreate/reauthorize** the instance. Verify your token is valid.

#### Internal error / timeouts when hitting `/elements/api-v2/...`

* Ensure the path matches what API Docs shows for your element (for Swagger imports, it’s typically `/elements/api-v2/v2/...`).

#### Double `/v2` or wrong base

* Keep **Base URL** `https://app.enlyze.com/api/` and **resource paths** `/v2/...` as imported by Swagger.

### Appendix — Examples

#### Example: cURL via Open Connectors instance (API Docs style)

```bash
curl -X GET \
  "https://api.openconnectors.<region>.ondemand.com/elements/api-v2/v2/machines"  \
  -H "Accept: application/json" \
  -H "Authorization: User <USER_SECRET>, Organization <ORG_SECRET>, Element <ELEMENT_TOKEN>"
```

#### Example: Direct ENLYZE cURL (bypasses Open Connectors)

```bash
curl -X GET "https://app.enlyze.com/api/v2/machines" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer <YOUR_ENLYZE_API_KEY>"
```

> Use the **direct** call only for local debugging. In SAP you should call through your **connector instance** so that logs, throttling, and mappings apply.
