<!-- llms.txt: https://workos.com/llms.txt -->

# Audit Log Schema

An object representing an Audit Log Schema.

## Create Schema

Creates a new Audit Log schema used to validate the payload of incoming Audit Log Events. If the `action` does not exist, it will also be created.

:::code-group{title="Request"}

```bash language="curl"
curl --request POST \
  --url https://api.workos.com/audit_logs/actions/user.viewed_invoice/schemas \
  --header "Authorization: Bearer sk_example_123456789" \
  --header "Content-Type: application/json" \
  -d @- <<BODY
  {
    "actor": {
      "metadata": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string"
          }
        }
      }
    },
    "targets": [
      {
        "type": "invoice",
        "metadata": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string"
            }
          }
        }
      }
    ],
    "metadata": {
      "type": "object",
      "properties": {
        "transactionId": {
          "type": "string"
        }
      }
    }
  }
BODY
```

```js language="js"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const schema = await workos.auditLogs.createSchema({
  action: 'user.viewed_invoice',
  actor: {
    metadata: {
      role: 'string',
    },
  },
  targets: [
    {
      type: 'user',
      metadata: {
        status: 'string',
      },
    },
  ],
  metadata: {
    invoice_id: 'string',
  },
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.audit_logs.create_schema(
  action_name: "user.logged_in",
  targets: [
    {
      type: "invoice",
      metadata: { type: "object", properties: { cost: { type: "number" } } }
    }
  ]
)
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.audit_logs.create_schema(
    action_name="user.logged_in",
    targets=[
        {
            "type": "invoice",
            "metadata": {"type": "object", "properties": {"cost": {"type": "number"}}},
        }
    ],
)
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.AuditLogs().CreateSchema(context.Background(), "user.logged_in", &workos.AuditLogsCreateSchemaParams{
		Targets: []any{
			map[string]any{
				"type": "invoice",
				"metadata": map[string]any{
					"type":       "object",
					"properties": map[string]any{"cost": map[string]any{"type": "number"}},
				},
			},
		},
	})
	if err != nil {
		panic(err)
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->auditLogs()->createSchema(
    actionName: "user.logged_in",
    targets: [
        [
            "type" => "invoice",
            "metadata" => [
                "type" => "object",
                "properties" => ["cost" => ["type" => "number"]],
            ],
        ],
    ],
);
```

```java language="java"
import com.workos.WorkOS;
import com.workos.auditlogs.AuditLogsApi.CreateSchemaOptions;

WorkOS workos = new WorkOS("sk_example_123456789");

CreateSchemaOptions options = CreateSchemaOptions.builder()
                                  .targets(List.of(Map.of("type",
                                      "invoice",
                                      "metadata",
                                      Map.of("type",
                                          "object",
                                          "properties",
                                          Map.of("cost", Map.of("type", "number"))))))
                                  .build();

workos.auditLogs.createSchema("user.logged_in", options);
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.AuditLogs.CreateSchemaAsync("user.logged_in", new AuditLogsCreateSchemaOptions {
    Targets =
        new[] {
            new Dictionary<string, object> {
                { "type", "invoice" },
                { "metadata",
                  new Dictionary<string, object> {
                      { "type", "object" },
                      { "properties",
                        new Dictionary<string, object> {
                            { "cost",
                              new Dictionary<string, object> {
                                  { "type", "number" },
                              } },
                        } },
                  } },
            },
        },
});
```

```rust language="rust"
use workos::Client;
use workos::audit_logs::CreateSchemaParams;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .audit_logs()
        .create_schema(
            "user.logged_in",
            CreateSchemaParams {
                targets: vec![
                    serde_json::json!({
                        "type": "invoice",
                        "metadata": serde_json::json!({
                            "type": "object",
                            "properties": serde_json::json!({ "cost": serde_json::json!({ "type": "number" }) }),
                        }),
                    }),
                ],
                ..Default::default()
            }
        )
        .await?;

    Ok(())
}
```

:::

## List Actions

Get a list of all Audit Log actions in the current environment.

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/audit_logs/actions" \
  --header "Authorization: Bearer sk_example_123456789"
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.audit_logs.list_actions
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.audit_logs.list_actions()
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.AuditLogs().ListActions(context.Background())
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->auditLogs()->listActions();
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.auditLogs.listActions();
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.AuditLogs.ListActionsAsync();
```

```rust language="rust" title="Request" tab="1"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .audit_logs()
        .list_actions()
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "object": "list",
  "data": [
    {
      "object": "audit_log_action",
      "name": "user.viewed_invoice",
      "schema": {
        "object": "audit_log_schema",
        "version": 1,
        "actor": {
          "metadata": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string"
              }
            }
          }
        },
        "targets": [
          {
            "type": "invoice",
            "metadata": {
              "type": "object",
              "properties": {
                "cost": {
                  "type": "number"
                }
              }
            }
          }
        ],
        "metadata": {
          "type": "object",
          "properties": {
            "transactionId": {
              "type": "string"
            }
          }
        },
        "created_at": "2026-01-15T12:00:00.000Z"
      },
      "created_at": "2026-01-15T12:00:00.000Z",
      "updated_at": "2026-01-15T12:00:00.000Z"
    }
  ],
  "list_metadata": {
    "before": "ala_01HXYZ123456789ABCDEFGHIJ",
    "after": "ala_01HXYZ987654321KJIHGFEDCBA"
  }
}
```

:::

## List Schemas

Get a list of all schemas for the Audit Logs action identified by `:name`.

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/audit_logs/actions/user.logged_in/schemas" \
  --header "Authorization: Bearer sk_example_123456789"
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.audit_logs.list_action_schemas(action_name: "user.logged_in")
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.audit_logs.list_action_schemas(action_name="user.logged_in")
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.AuditLogs().ListActionSchemas(context.Background(), "user.logged_in")
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->auditLogs()->listActionSchemas(actionName: "user.logged_in");
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.auditLogs.listActionSchemas("user.logged_in");
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.AuditLogs.ListActionSchemasAsync("user.logged_in");
```

```rust language="rust" title="Request" tab="1"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .audit_logs()
        .list_action_schemas("user.logged_in")
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "object": "list",
  "data": [
    {
      "object": "audit_log_schema",
      "version": 1,
      "actor": {
        "metadata": {
          "type": "object",
          "properties": {
            "role": {
              "type": "string"
            }
          }
        }
      },
      "targets": [
        {
          "type": "invoice",
          "metadata": {
            "type": "object",
            "properties": {
              "cost": {
                "type": "number"
              }
            }
          }
        }
      ],
      "metadata": {
        "type": "object",
        "properties": {
          "transactionId": {
            "type": "string"
          }
        }
      },
      "created_at": "2026-01-15T12:00:00.000Z"
    }
  ],
  "list_metadata": {
    "before": "als_01HXYZ123456789ABCDEFGHIJ",
    "after": "als_01HXYZ987654321KJIHGFEDCBA"
  }
}
```

:::

### audit_log_schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | "audit_log_schema" | Yes | Distinguishes the Audit Log Schema object. |
| `version` | number | Yes | The version of the schema. |
| `targets` | array | Yes | The list of targets for the schema. |
| `actor` | object | Yes | The metadata schema for the actor. |
| `metadata` | object | Yes | Additional data that should be associated with the event or entity. There is a limit of 50 keys. Key names can be up to 40 characters long, and values can be up to 500 characters long. |

### POST /audit_logs/actions/{actionName}/schemas

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `actor` | object | No | The metadata schema for the actor. |
| `targets` | object[] | Yes | The list of targets for the schema. |
| `metadata` | object | No | Optional JSON schema for event `metadata` |

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `actionName` | string | Yes | The name of the Audit Log action. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `audit_log_schema` | object | Distinguishes the Audit Log Schema object. |

### GET /audit_logs/actions

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `before` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `after` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `limit` | integer | No | Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`. |
| `order` | "normal" \| "desc" \| "asc" | No | Order the results by the creation time. Defaults to `normal`. |

### GET /audit_logs/actions/{actionName}/schemas

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `actionName` | string | Yes | The name of the Audit Log action. |
| `before` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `after` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `limit` | integer | No | Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`. |
| `order` | "normal" \| "desc" \| "asc" | No | Order the results by the creation time. Defaults to `normal`. |