> For the complete documentation index, see [llms.txt](https://docs.medable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.medable.com/cortex-api/scripting/audit.md).

# Audit

## Static method&#x20;

### record(title, objectId, action, options)

*Arguments*

* `title` { String }&#x20;
* `objectId` { ObjectID }
* `action` { String } For example, create, read, update, delete, access, and transfer
* `options` { Object } Options object
  * `metadata` { Object }
  * `err` {Fault}

## Associate audit logs with custom objects

You can associate audit logs with custom objects using a script to add custom property information to the audit logs.

This only applies to **user** audit events in the subcategories listed below.

**create** ​ ​​

`audit.record('my_object', _id, 'create', {metadata: {message: 'Create custom object'}})​​ ​ ​ ​`&#x20;

**read** ​ ​​&#x20;

`audit.record('my_object', _id, 'read', {metadata: {message: 'Read custom object'}}) ​​ ​ ​ ​`&#x20;

**update** ​&#x20;

`​​audit.record('my_object', _id, 'update', {metadata: {message: 'Update custom object'}})​​ ​ ​ ​`&#x20;

**delete** ​&#x20;

`​​audit.record('my_object', _id, 'delete', {metadata: {message: 'Delete custom object'}})​​ ​ ​` ​&#x20;

**access** ​&#x20;

`​​audit.record('my_object', _id, 'access', {metadata: {message: 'Access custom object'}})​​ ​ ​ ​`&#x20;

**transfer** ​&#x20;

`​audit.record('my_object', _id, 'transfer', {metadata: {message: 'Transfer custom object'}})​​ ​`

#### Example: Create audit record

```javascript
import audit from 'audit'

// Create custom object
org.objects.objects.insertOne({
    label: 'My Object',
    name: 'my_object',
    defaultAcl: 'owner.delete',
    createAcl: 'account.public',
    properties: [
      {
        label: 'name',
        name: 'c_name',
        type: 'String',
        indexed: true
      }
    ]
  })
  .execute()

// Create audit record
return audit.record('my_object', org.objects.my_object._id, 'create', {
  metadata: {
    message: 'record created'
  }
})
```

## Object schema

```
{
    "ETag": "9984ad7455e8b36d32bc7395ca0148d9",
    "_id": "436f6e746578742041756474",
    "allowConnections": false,
    "auditing": {
        "all": false,
        "category": "audit",
        "changes": false,
        "enabled": false,
        "updateSubcategory": "update"
    },
    "connectionOptions": {
        "requireAccept": true,
        "requiredAccess": 5,
        "sendNotifications": true
    },
    "createAcl": [],
    "custom": false,
    "defaultAcl": [],
    "extended": true,
    "extensible": false,
    "feedDefinition": [],
    "hasETag": false,
    "isUnmanaged": true,
    "isVersioned": false,
    "label": "Audit",
    "name": "audit",
    "object": "schema",
    "pluralName": "audits",
    "properties": [
        {
            "fqpp": "audit._id",
            "indexed": true,
            "label": "Id",
            "name": "_id",
            "read": 1,
            "readOnly": true,
            "type": "ObjectId"
        },
        {
            "fqpp": "audit.object",
            "indexed": true,
            "label": "Object",
            "name": "object",
            "read": 1,
            "readOnly": true,
            "type": "String"
        },
        {
            "fqpp": "audit.access",
            "label": "Access Level",
            "name": "access",
            "read": 1,
            "readOnly": true,
            "type": "Number"
        },
        {
            "fqpp": "audit.propertyAccess",
            "label": "Property Access",
            "name": "propertyAccess",
            "optional": true,
            "read": 1,
            "readOnly": true,
            "type": "Document"
        },
        {
            "fqpp": "audit.req",
            "indexed": true,
            "label": "Request Id",
            "name": "req",
            "read": 4,
            "readOnly": true,
            "type": "ObjectId"
        },
        {
            "fqpp": "audit.principal",
            "indexed": true,
            "label": "Principal",
            "name": "principal",
            "read": 4,
            "readOnly": true,
            "type": "ObjectId"
        },
        {
            "fqpp": "audit.ipv4",
            "indexed": true,
            "label": "IP Address",
            "name": "ipv4",
            "read": 4,
            "readOnly": true,
            "type": "Number"
        },
        {
            "fqpp": "audit.cat",
            "indexed": true,
            "label": "Category",
            "name": "cat",
            "read": 4,
            "readOnly": true,
            "type": "String"
        },
        {
            "fqpp": "audit.sub",
            "indexed": true,
            "label": "Sub Category",
            "name": "sub",
            "read": 4,
            "readOnly": true,
            "type": "String"
        },
        {
            "fqpp": "audit.context",
            "label": "Context",
            "name": "context",
            "properties": [
                {
                    "fqpp": "audit.context.object",
                    "indexed": true,
                    "label": "Object",
                    "name": "object",
                    "read": 4,
                    "readOnly": true,
                    "type": "String"
                },
                {
                    "fqpp": "audit.context._id",
                    "indexed": true,
                    "label": "Identifier",
                    "name": "_id",
                    "read": 4,
                    "readOnly": true,
                    "type": "ObjectId"
                }
            ],
            "read": 4,
            "readOnly": true,
            "type": "Document"
        },
        {
            "fqpp": "audit.ac",
            "label": "Access Context",
            "name": "ac",
            "read": 4,
            "readOnly": true,
            "type": "Any"
        },
        {
            "fqpp": "audit.metadata",
            "label": "Metadata",
            "name": "metadata",
            "read": 4,
            "readOnly": true,
            "type": "Any"
        },
        {
            "fqpp": "audit.err",
            "label": "Error",
            "name": "err",
            "read": 4,
            "readOnly": true,
            "type": "Any"
        }
    ],
    "shareAcl": [],
    "shareChain": [
        5,
        2
    ]
}
```
