# 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 Token** and a **PreRequest Hook** to inject the upstream `Authorization: Bearer <token>` 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_TOKEN>`.

> 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

* ENLYZE **API token** for the target tenant.
* 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-d7a9e8bceef7eff2b6d150432302156ec65c9047%2Fsap-open-connectors-overview-01.png?alt=media" alt=""><figcaption></figcaption></figure>

### Step 1: Import the ENLYZE OpenAPI

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

   <figure><img src="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-f0ec528b254d3a4c5ed57365bcf5f39d68ce3d0a%2Fsap-open-connectors-create-01.png?alt=media" alt=""><figcaption></figcaption></figure>

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

   <figure><img src="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-8f53e19973a8a6b441fee60ef678bae6d3c2ec3b%2Fsap-open-connectors-create-02.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-8d242d12b1ae8d9ddcedacac83a4362988e00468%2Fsap-open-connectors-config-01.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-c8da76c6242223804e9f96becb9cdc9f12c28d09%2Fsap-open-connectors-config-02.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-b0902c428aa0c94d1bf13b4dadf3e43cc0458417%2Fsap-open-connectors-auth-01.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-c9ae8c6b36bc7274b5faa07bf81bdecf4136bf8e%2Fsap-open-connectors-auth-02.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-fba80662d4b8dbdb85356b038590ad21f060881d%2Fsap-open-connectors-test-01.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-b681a9f8bd83fbe4b943ca215ac83b127a281682%2Fsap-open-connectors-test-02.png?alt=media" 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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-49e53ebcaf7a4406564be00cdc7b64863545b16e%2Fsap-open-connectors-test-03.png?alt=media" 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 token>`

> **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="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-f443db8ee96138bbcfa3e15f197c225dda858776%2Fsap-open-connectors-result-01.png?alt=media" alt=""><figcaption></figcaption></figure>

Successful response:

<figure><img src="https://4261006941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNEuiyRRKwuqtIcaEt45%2Fuploads%2Fgit-blob-3288cd94430fbd838f6b36a6f9772da49cf6f5ab%2Fsap-open-connectors-result-02.png?alt=media" 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_TOKEN>"
```

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