> For the complete documentation index, see [llms.txt](https://algolytics-technologies.gitbook.io/algolytics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algolytics-technologies.gitbook.io/algolytics/event-engine-user/examples-of-api-operations.md).

# Examples of API operations

## Sending a JSON with an event <a href="#sending-a-json-with-an-event" id="sending-a-json-with-an-event"></a>

**Example of a file containing a package of statements:**

```
[
{"userId":1,"eventId":1,"time":1463988845701,"zm1":5,"zm2":8},
{"userId":1,"eventId":1,"time":1463988845709,"zm1":55,"zm2":55}
]
```

**Example of a client query:**

```
wget -q -O - --post-file=test.json https://localhost:8321/event?appid=3697
```

**Example of a response:**

```
[
{"userId":1,"scores":[{"modelId":1,"score":1.0}]},
{"userId":1,"scores":[{"modelId":1,"score":0.6}]}
]
```

**Parameters**

| Name      | Description                                                     | Obligatory |
| --------- | --------------------------------------------------------------- | ---------- |
| appid     | Client id                                                       | Yes        |
| ts        | Time in miliseconds (field name can be modified in config file) | Yes        |
| event\_id | Event type (field name can be modified in config file)          | Yes        |
| user\_id  | User id (field name can be modified in config file)             | Yes        |

**Response codes**

| Name          | Output JSON                          | Cause                     |
| ------------- | ------------------------------------ | ------------------------- |
| 403 Forbidden |                                      | No appid                  |
| 200           | "error": "Error during json parsing" | Error during json parsing |

## Query about user's profile (list of aggregates) <a href="#query-about-users-profile-list-of-aggregates" id="query-about-users-profile-list-of-aggregates"></a>

**Example of a client query:**

```
wget -q -O - "https://178.33.61.90:8323/profile?appid=3697&userid=AB123"
```

**Example of a response:**

```
{"agg1_last_value_all":5.0,"agg2_last_value_all":"AAA","agg3_cnt_all":3.0," agg3_sum_all":2330.0}
```

**Parameters**

| Name   | Description | Obligatory |
| ------ | ----------- | ---------- |
| appid  | Client id   | Yes        |
| userid | User id     | Yes        |

**Response codes**

| Name            | Output JSON | Cause     |
| --------------- | ----------- | --------- |
| 403 Forbidden   |             | No appid  |
| 400 Bad request |             | No userid |

## Adding a model <a href="#adding-a-model" id="adding-a-model"></a>

**Example of a client query:**

```
wget -qO- --post-data='{"use_category":0, "value":0.6, "category_id":0.6, "client_value":0.6, "positive_target_cnt":0.6, "excluded":["www.wp.pl", "www.onet.pl"]}' http:// localhost:8323/models?appid=3697&modelid=123
```

**Example of a response:**

{} - no error

**Parameters**

| Name                  | Description                                                                                 | Obligatory              |
| --------------------- | ------------------------------------------------------------------------------------------- | ----------------------- |
| appid                 | Client id                                                                                   | Yes                     |
| modelid               | Model id                                                                                    | Yes                     |
| value                 | CPC (in programmatic)                                                                       | Yes                     |
| client\_value         | Client CPC (in programmatic)                                                                | No                      |
| use\_category         | If 1 - model will be buid on categories, if 0 - model will be build on campaigns            | Yes                     |
| category\_id          | Model category id (in programmatic - campaign category)                                     | Yes, if use\_category=1 |
| positive\_target\_cnt | In programmatic - a number of ordered clicks                                                | No                      |
| excluded or included  | List of urls to exclude or include in a model (it could be either exclude or include field) | No                      |

**Response codes**

| Name            | Output JSON                                                                    | Cause                                                      |
| --------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| 403 Forbidden   |                                                                                | No appid                                                   |
| 404 Not Found   |                                                                                | No modelid                                                 |
| 400 Bad request |                                                                                | Invalid format of modelid                                  |
| 200             | "error": "Parameter use\_category must be set and must be an integer (0 or 1)" | No use\_category or invalid format                         |
| 200             | "error": "Parameter value must be set and must be numeric"                     | No value or invalid format                                 |
| 200             | "error": "Parameter category\_id must be provided if use\_category=1"          | No category\_id while use\_category=1                      |
| 200             | "error": "Exactly one parameter must be set (either included or excluded)"     | No excluded/included set or both excluded and included set |

## Model desactivation <a href="#model-desactivation" id="model-desactivation"></a>

**Example of a client query:**

```
wget -qO- --delete http:// localhost:8323/models?appid=3697&modelid=123
```

**Example of a response:**

{} - no error

**Parameters**

| Name    | Description | Obligatory |
| ------- | ----------- | ---------- |
| appid   | Client id   | Yes        |
| modelid | Model id    | Yes        |

**Response codes**

| Name            | Output JSON                      | Cause                     |
| --------------- | -------------------------------- | ------------------------- |
| 403 Forbidden   |                                  | No appid                  |
| 404 Not Found   |                                  | No modelid                |
| 400 Bad request |                                  | Invalid format of modelid |
| 200             | "error": "model does not exist." | The model does not exist  |

## Adding urls to exclude/include during modeling (in programmatic) <a href="#adding-urls-to-excludeinclude-during-modeling-in-programmatic" id="adding-urls-to-excludeinclude-during-modeling-in-programmatic"></a>

**Example of a client query:**

```
wget -qO- --post-data='{"excluded":["www.wp.pl", "www.onet.pl"]}'         http:// localhost:8323/urls?appid=3697&modelid=123
```

**Example of a response:**

{} - no error

**Parameters**

| Name                 | Description                                          | Obligatory |
| -------------------- | ---------------------------------------------------- | ---------- |
| appid                | Client id                                            | Yes        |
| modelid              | Model id                                             | Yes        |
| excluded or included | A list of urls to exclude or include during modeling | Yes        |

**Response codes**

| Name            | Output JSON                                                                 | Cause                                                      |
| --------------- | --------------------------------------------------------------------------- | ---------------------------------------------------------- |
| 403 Forbidden   |                                                                             | No appid                                                   |
| 404 Not Found   |                                                                             | No modelid                                                 |
| 400 Bad request |                                                                             | Invalid format of modelid                                  |
| 200             | "error": "Exactly one parameter must be set (either included or excluded)"" | No excluded/included set or both excluded and included set |

## Downloading information about chosen model <a href="#downloading-information-about-chosen-model" id="downloading-information-about-chosen-model"></a>

**Example of a client query:**

```
wget -qO- --get http:// localhost:8323/models?appid=3697&modelid=115
```

**Example of a response:**

```
{
"model_id": 115,
"active": 1,
"used": 0,
"first_model_time": null,
"saved_model_time": null,
"value": 6,
"client_value": 0.3,
"positive_target_cnt": 10000,
"category_id": 9,
"use_category": 0,
"end_date": "1970-01-01 00:00:00"
}
```

**Parameters**

| Name    | Description | Obligatory                                 |
| ------- | ----------- | ------------------------------------------ |
| appid   | Client id   | Yes                                        |
| modelid | Model id    | No - if empty, all models will be returned |

**Response codes**

| Name            | Output JSON | Cause                     |
| --------------- | ----------- | ------------------------- |
| 403 Forbidden   |             | No appid                  |
| 400 Bad request |             | Invalid format of modelid |
| 200             | {}          | The model does not exist  |

## Downloading information about all models <a href="#downloading-information-about-all-models" id="downloading-information-about-all-models"></a>

**Example of a client query:**

```
wget -qO- --get http:// localhost:8323/models?appid=3697
```

**Example of a response:**

```
[
{
"model_id": 111,
"active": 1,
"used": 0,
"first_model_time": null,
"saved_model_time": null,
"value": 6,
"client_value": 0.2,
"positive_target_cnt": 10000,
"category_id": 5,
"use_category": 1,
"end_date": null
},
  {
"model_id": 112,
"active": 1,
"used": 0,
"first_model_time": null,
"saved_model_time": null,
"value": 6,
"client_value": 0.2,
"positive_target_cnt": 10000,
"category_id": 0,
"use_category": 0,
"end_date": "2018-02-28 04:00:02"
}
]
```

**Parameters**

| Name  | Description | Obligatory |
| ----- | ----------- | ---------- |
| appid | Client id   | Yes        |

**Response codes**

| Name | Output JSON | Cause                                |
| ---- | ----------- | ------------------------------------ |
| \[]  |             | There are no models for chosen appid |

## Downloading information about used/unused, active models <a href="#downloading-information-about-usedunused-active-models" id="downloading-information-about-usedunused-active-models"></a>

**Example of a client query:**

```
wget -qO- --get http:// localhost:8323/models?appid=3697&used=1
```

**Example of a response:**

```
[1018,1312,1314,1315,1319,1355,1378,1379,1391,1398] 
```

**Parameters**

| Name  | Description                                                                                                              | Obligatory |
| ----- | ------------------------------------------------------------------------------------------------------------------------ | ---------- |
| appid | Client id                                                                                                                | Yes        |
| used  | 1 - list of used models in on-line scoring (active=1 and used=1 in metadata), 0 - list of active models, but with used=0 |            |

**Response codes**

| Name | Output JSON | Cause                                               |
| ---- | ----------- | --------------------------------------------------- |
| \[]  |             | There are no models for chosen appid and used value |
