# Audit Log API

The **Audit Log API** provides endpoints for retrieving records of actions and changes within your Nected workspace. These logs are essential for tracking user activities, monitoring changes, and maintaining security within the workspace.

All Audit Log API endpoints require an authenticated request using the **`nected-api-key`** header. This key is specific to your workspace and must be kept secure.

> Note: By default, the nected-api-key is set to private for security purposes. To retrieve your nected-api-key, follow these steps:
>
> 1. Log in to [Nected](https://app.nected.ai/credentials).
> 2. Go to **Authorization** page from the left sidebar
> 3. View or regenerate your `nected-api-key` to use in API requests.

For easier testing and exploration, the **Audit Log API** endpoints are available in a [**Postman Collection**](https://www.postman.com/tech-team-1209/nected-public-workspace/collection/io6frwr/nected-management-api-s).

***

## Endpoints

### 1. Get All Audit Logs

Retrieve a paginated list of audit logs for a specified module within your workspace. This endpoint is useful for monitoring actions performed by users in different modules.

**Endpoint**: `GET /dev/audit/audit/search`

**Method**: `GET`

**Description**: Retrieves a list of audit logs for a specified module in your workspace.

#### Request Parameters

* **Headers**:
  * **`nected-api-key`** *(string, required)* - Your API key to authenticate and link the request to your workspace. [Learn how to get it here](https://app.nected.ai/credentials).
* **Query Parameters**:
  * **`pageNo`** *(integer, optional)* - Page number for paginated results. Default is 1.
  * **`pageSize`** *(integer, optional)* - Number of records per page. Default is 10, maximum is 10.
  * **`search` -** rule\_name or any text
  * **`type`** - Type can be anything among these: ruleSet | simpleRule | dataSet | connector | globalVar | decisionTable | systemAPIKey | authConfig | cron | workflow,nectedWorkflow | api | delay | webhook&#x20;
  * **`event`** In events you can set these: test | api | roleRevoke | roleUpdate | cronTest | cron | webhook | delayedTest | delay&#x20;
  * **`status`** - Status can be success,Completed | error,Failed environment production | staging startDate date endDate date

#### Example Request

```
curl --location 'https://api.nected.ai/dev/audit/audit/search?pageNo=1&pageSize=5' \
--header 'nected-api-key: YOUR_API_KEY'

```

#### Response Parameters

* **logId** *(string)* - Unique identifier of the audit log entry.
* **timestamp** *(integer)* - Unix timestamp indicating when the action was performed.
* **user** *(string)* - Identifier of the user who performed the action.
* **action** *(string)* - Type of action recorded (e.g., `create`, `update`, `delete`).
* **module** *(string)* - Module where the action occurred.
* **details** *(object)* - Additional information about the action, such as affected entities or parameters.

#### Example Response

```json
{
    "totalCount": 44,
    "totalPages": 9,
    "pageNo": 1,
    "pageSize": 5,
    "data": [
        {
            "entityId": "",
            "executionId": "1236ef60-c66a-425b-9932-4432dc502254",
            "type": "Decisiontable",
            "name": "Amazon DP",
            "event": "Update",
            "status": "Success",
            "environment": "Staging",
            "user": "Snehasish Konger",
            "workspaceId": "60",
            "ip": "121.240.111.38",
            "logId": "cIQ1bJMBXygxw2IbFdqi",
            "statusTimeMs": 0,
            "date": "2024-11-27T06:00:38.470511956Z",
            "rootNode": {
                "id": "",
                "name": "",
                "logId": ""
            },
            "traceId": "4d693277-9509-4afa-a1af-f78d80bf74f3",
            "message": "",
            "input": null,
            "output": null,
            "path": null,
            "version": "draft"
        },
        {
            "entityId": "",
            "executionId": "123e4e82-4ddf-40de-bdb2-d7ed1ae1697f",
            "type": "Api",
            "name": "Amazon DP",
            "event": "Call Via API",
            "status": "Error",
            "environment": "Staging",
            "user": "",
            "workspaceId": "60",
            "ip": "121.240.111.38",
            "logId": "lIQtbJMBXygxw2IbjNhm",
            "statusTimeMs": 4,
            "date": "2024-11-27T05:52:24.662785492Z",
            "rootNode": {
                "id": "123e4e82-4ddf-40de-bdb2-d7ed1ae1697f",
                "name": "Amazon DP",
                "logId": "123e4e82-4ddf-40de-bdb2-d7ed1ae1697f"
            },
            "traceId": "Root=1-6746b398-53e5e9017fd84ff46c030f27",
            "message": "missing required params key countrycode",
            "input": null,
            "output": null,
            "path": [],
            "version": "draft"
        },
        {
            "entityId": "",
            "executionId": "659993bd3e1ce3c24b4760c2",
            "type": "Dataset",
            "name": "New_Orders_Ecomm 1704563645284",
            "event": "Update",
            "status": "Success",
            "environment": "Staging",
            "user": "Snehasish Konger",
            "workspaceId": "60",
            "ip": "121.240.111.38",
            "logId": "roIAY5MBXygxw2IbQLXe",
            "statusTimeMs": 0,
            "date": "2024-11-25T11:06:21.080089979Z",
            "rootNode": {
                "id": "",
                "name": "",
                "logId": ""
            },
            "traceId": "a713a9ae-9ee1-446e-aaed-43fc8b1424af",
            "message": "",
            "input": null,
            "output": null,
            "path": null,
            "version": "draft"
        },
        {
            "entityId": "",
            "executionId": "test_dataSet:60:00181f5d-f407-4f57-8494-2320345a40e1:draft:ee3ce5ce-1a53-41f6-911b-5ec008d8beea",
            "type": "Dataset",
            "name": "Loyalty_Rule_Dataset",
            "event": "Test Via Console",
            "status": "Success",
            "environment": "Staging",
            "user": "",
            "workspaceId": "60",
            "ip": "43.205.43.45",
            "logId": "VYL5YpMBXygxw2Ib87RH",
            "statusTimeMs": 137,
            "date": "2024-11-25T10:59:28.061763152Z",
            "rootNode": {
                "id": "3d60030d-cf4e-4a6e-b860-6e90ec214ac6",
                "name": "Loyalty_Rule_Dataset",
                "logId": "3d60030d-cf4e-4a6e-b860-6e90ec214ac6"
            },
            "traceId": "339df9bc-c3dd-4223-888d-b37de965fecc",
            "message": "successfully executed dataset Loyalty_Rule_Dataset",
            "input": null,
            "output": null,
            "path": [],
            "version": "draft"
        },
        {
            "entityId": "",
            "executionId": "test_connector:60:658dc072df38777379927f9e:0.10:f5af6c7e-8fdb-417f-b761-c83df28ce67f",
            "type": "Connector",
            "name": "NewDemoDB",
            "event": "Test Via Console",
            "status": "Success",
            "environment": "Staging",
            "user": "",
            "workspaceId": "60",
            "ip": "43.205.43.45",
            "logId": "HoJdYpMBXygxw2IbqZJw",
            "statusTimeMs": 748,
            "date": "2024-11-25T08:08:44.930424286Z",
            "rootNode": {
                "id": "029d2110-47a9-4b84-bc51-1ce5141ee61e",
                "name": "NewDemoDB",
                "logId": "029d2110-47a9-4b84-bc51-1ce5141ee61e"
            },
            "traceId": "5648bdec-3559-4079-8d96-e54e8be6b815",
            "message": "successfully executed connector NewDemoDB",
            "input": null,
            "output": null,
            "path": [],
            "version": "0.10"
        }
    ],
    "code": "success",
    "message": "success."
}
```

#### Errors

* **401 Unauthorized**: Missing or invalid `nected-api-key`.
  * **Example**: `{"error": "Unauthorized access. Invalid API key."}`
* **404 Not Found**: Specified module does not exist in the workspace.
  * **Example**: `{"error": "Module not found."}`

***

### 2. Get Audit Log Detail

Retrieve detailed information for a specific audit log entry. This endpoint provides in-depth information about a particular action.

**Endpoint**: `GET /dev/audit/audit/:log-id`

**Method**: `GET`

**Description**: Retrieves details of a specific audit log entry by `log-id` within the specified module.

#### Request Parameters

* **Headers**:
  * **`nected-api-key`** *(string, required)* - Your API key to authenticate and link the request to your workspace.
* **Path Parameters**:
  * **`log-id`** *(string, required)* - The unique identifier for the specific audit log entry.

#### Example Request

```
curl --location 'https://api.nected.ai/dev/audit/audit/:logid' \
--header 'nected-api-key: YOUR_API_KEY'
```

#### Response Parameters

* **logId** *(string)* - Unique identifier of the audit log entry.
* **timestamp** *(integer)* - Unix timestamp when the action occurred.
* **user** *(string)* - Identifier of the user who performed the action.
* **action** *(string)* - Type of action recorded.
* **module** *(string)* - Module within which the action took place.
* **description** *(string)* - A detailed description of the action taken.
* **details** *(object)* - Additional data related to the action, such as the affected entity and fields.

#### Example Response

```json
{
    "type": "object",
    "properties": {
        "pageNo": {
            "type": "integer"
        },
        "pageSize": {
            "type": "integer"
        },
        "data": {
            "type": "object",
            "properties": {
                "detail": {
                    "type": "object",
                    "properties": {
                        "entityId": {
                            "type": "string"
                        },
                        "executionId": {
                            "type": "string"
                        },
                        "type": {
                            "type": "string"
                        },
                        "name": {
                            "type": "string"
                        },
                        "event": {
                            "type": "string"
                        },
                        "status": {
                            "type": "string"
                        },
                        "environment": {
                            "type": "string"
                        },
                        "user": {
                            "type": "string"
                        },
                        "workspaceId": {
                            "type": "string"
                        },
                        "ip": {
                            "type": "string"
                        },
                        "logId": {
                            "type": "string"
                        },
                        "statusTimeMs": {
                            "type": "integer"
                        },
                        "date": {
                            "type": "string"
                        },
                        "rootNode": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "name": {
                                    "type": "string"
                                },
                                "logId": {
                                    "type": "string"
                                }
                            }
                        },
                        "traceId": {
                            "type": "string"
                        },
                        "message": {
                            "type": "string"
                        },
                        "input": {
                            "type": ["object", "null"]
                        },
                        "output": {
                            "type": ["object", "null"]
                        },
                        "path": {
                            "type": ["string", "null"]
                        },
                        "version": {
                            "type": "string"
                        }
                    }
                },
                "parent": {
                    "type": "array",
                    "items": {}
                },
                "children": {
                    "type": "array",
                    "items": {}
                },
                "totalChildren": {
                    "type": "integer"
                }
            }
        },
        "code": {
            "type": "string"
        },
        "message": {
            "type": "string"
        }
    }
}
```

#### Errors

* **401 Unauthorized**: Missing or invalid `nected-api-key`.
  * **Example**: `{"error": "Unauthorized access. Invalid API key."}`
* **404 Not Found**: Specified `log-id` not found within the module.
  * **Example**: `{"error": "Audit log entry not found."}`

***

### Error Responses

The Audit Log API may return specific errors if the request fails. Common error responses include:

* **401 Unauthorized**: Indicates that the `nected-api-key` is missing or invalid. Ensure that you are using the correct API key for your workspace.
  * **Example Response**:

    ```json
    {
      "error": "Unauthorized access. Invalid API key."
    }

    ```
* **404 Not Found**: This error occurs if the specified module or log ID does not exist in the workspace.
  * **Example Response**:

    ```json
    {
      "error": "Module not found."
    }

    ```
  * **Example Response for log ID**:

    ```json
    {
      "error": "Audit log entry not found."
    }

    ```

***

### Pagination

The `Get All Audit Logs` endpoint supports pagination to help manage large sets of audit records. The following query parameters control pagination:

* **`pageNo`** *(integer, optional)* - Specifies the page number to retrieve, with a default of 1.
* **`pageSize`** *(integer, optional)* - Specifies the number of records per page, with a default of 10 and a maximum of 10.

Example usage of pagination in the API:

```json
curl --location 'https://api.nected.ai/dev/audit/audit/search?pageNo=1&pageSize=5' \
--header 'nected-api-key: YOUR_API_KEY'
```

***

This concludes the **Audit Log API Documentation**. These endpoints provide secure and comprehensive access to audit logs within your Nected workspace, empowering you to track and review actions for improved security and operational oversight.


---

# 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.nected.ai/nected-docs/management-api/audit-log-api.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.
