# Server-side Conversions

Optibase exposes an API endpoint you can call from the server to trigger a Conversion.

#### Endpoint

**URL**: `https://app.optibase.io/api/script/conversionEvent`

**Method**: `POST`

#### Headers

* **Content-Type**: `application/json`

#### Request Body

The body must be a JSON object that contains the following fields:

* **publicApiKey** (string): [#public-api-key](#public-api-key "mention")
* **userFriendlyConversionId** (string): [#user-friendly-conversion-id](#user-friendly-conversion-id "mention")
* **testedUserId** or **testedUserExternalId** (string): [#tested-user-id](#tested-user-id "mention") or [#tested-user-external-id](#tested-user-external-id "mention")

**Sample Request Body**

```json
{
  "publicApiKey": "clv3047v70dsat664sgrzwotq",
  "userFriendlyConversionId": "serverside_conversion",
  "testedUserId": "clr6hq6y70001qv4jpwag4asd"
}
```

or

```json
{
  "publicApiKey": "clv3047v70dsat664sgrzwotq",
  "userFriendlyConversionId": "serverside_conversion",
  "testedUserExternalId": "id123"
}
```

### Public API Key

You can find it by going to your Workspace settings -> Public API Keys

### User-Friendly Conversion ID

Create a Programmatic Conversion and copy the ID by clicking on the copy field in the trigger column:<br>

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

### Tested User ID

When a user visits your page, the Custom Optibase Script generates a Tested User ID for the user. You will need to get this ID from the Optibase Script and store it on the server to call the Optibase API Endpoint later and trigger a Conversion for this specific user.

You get this from each user separately with custom JavaScript on the website where you have the Optibase Script setup. The Optibase Script assigns the generated Tested User ID to a global variable you can read with the custom JavaScript.

The global variable is `window.optibaseTestedUserId` which is a string.

### Tested User External ID

Alternatively, you can assign an External ID to the Tested User by calling `window.optibaseSetTestedUserExternalId(externalId: string): Promise<void>`

The External ID is usually the ID you have assigned to your user in your database.

If you do that, you can call the Optibase API Endpoint with that new External ID, and you don't have to store the Tested User ID mentioned above.

The Tested User External ID will then also be assigned to the global variable `window.optibaseTestedUserExternalId`.


---

# 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.optibase.io/features/conversions/server-side-conversions.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.
