---
descriptions:
  idempotency_key: A unique string to prevent duplicate requests.
  create_event:
    organization_id: The unique ID of the Organization.
    action: Identifier of what happened
    occurred_at: ISO-8601 value of when the action occurred
    version: What schema version the event is associated with
    actor:
      id: Actor identifier
      type: Actor type
      name: Optional actor name
    target:
      id: Target identifier
      type: Target type
      name: Optional target name
    context:
      location: IP Address or some other geolocation identifier
      user_agent: User agent string
    metadata: |
      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.
reference:
  curl:
    - key: create_event
      id: create_event
      url: /reference/audit-logs/create-event
      title: /audit_logs/events
      type: POST
      parameters:
        - key: organization_id
          type: string
          description: (create_event.organization_id)
        - key: event
          type: object
          expanded: true
          properties:
            - key: action
              type: string
              description: (create_event.action)
            - key: occurred_at
              type: string
              description: (create_event.occurred_at)
            - key: version
              type: number
              optional: true
              description: (create_event.version)
            - key: actor
              type: object
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.actor.type)
                - key: id
                  type: string
                  description: (create_event.actor.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: object
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: array
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.target.type)
                - key: id
                  type: string
                  description: (create_event.target.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: object
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: object
              expanded: true
              properties:
                - key: location
                  type: string
                  description: (create_event.context.location)
                - key: user_agent
                  type: string
                  optional: true
                  description: (create_event.context.user_agent)
            - key: metadata
              type: object
              optional: true
              description: (create_event.metadata)
  js:
    - key: createEvent
      id: create_event
      url: /reference/audit-logs/create-event
      title: auditLogs.createEvent()
      parameters:
        - key: organizationId
          type: string
          description: (create_event.organization_id)
        - key: event
          type: object
          expanded: true
          properties:
            - key: action
              type: string
              description: (create_event.action)
            - key: occurredAt
              type: Date
              description: (create_event.occurred_at)
            - key: version
              type: number
              optional: true
              description: (create_event.version)
            - key: actor
              type: AuditLogActor
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.actor.type)
                - key: id
                  type: string
                  description: (create_event.actor.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: object
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: 'AuditLogTarget[]'
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.target.type)
                - key: id
                  type: string
                  description: (create_event.target.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: object
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: object
              expanded: true
              properties:
                - key: location
                  type: string
                  description: (create_event.context.location)
                - key: userAgent
                  type: string
                  optional: true
                  description: (create_event.context.user_agent)
            - key: metadata
              type: object
              optional: true
              description: (create_event.metadata)
        - key: options
          type: object
          optional: true
          expanded: true
          properties:
            - key: idempotencyKey
              type: string
              description: (idempotency_key)
  java:
    - key: createEvent
      id: create_event
      url: /reference/audit-logs/create-event
      title: auditLogs.createEvent()
      parameters:
        - key: organizationId
          type: String
          description: (create_event.organization_id)
        - key: options
          type: CreateAuditLogEventOptions
          expanded: true
          properties:
            - key: action
              type: String
              description: (create_event.action)
            - key: occurredAt
              type: Date
              description: (create_event.occurred_at)
            - key: actor
              type: Actor
              expanded: true
              properties:
                - key: id
                  type: String
                  description: (create_event.actor.id)
                - key: type
                  type: String
                  description: (create_event.actor.type)
                - key: name
                  type: String
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: 'Map<String, String>'
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: List<Target>
              expanded: true
              properties:
                - key: id
                  type: String
                  description: (create_event.target.id)
                - key: type
                  type: String
                  description: (create_event.target.type)
                - key: name
                  type: String
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: 'Map<String, String>'
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: Context
              expanded: true
              properties:
                - key: location
                  type: String
                  description: (create_event.context.location)
                - key: userAgent
                  type: String
                  optional: true
                  description: (create_event.context.user_agent)
            - key: version
              type: Int
              optional: true
              description: (create_event.version)
            - key: metadata
              type: 'Map<String, String>'
              optional: true
              description: (create_event.metadata)
        - key: reqOptions
          type: CreateAuditLogEventRequestOptions
          optional: true
          expanded: true
          properties:
            - key: idempotencyKey
              type: String
              description: (idempotency_key)
  dotnet:
    - key: CreateEvent
      id: create_event
      url: /reference/audit-logs/create-event
      title: auditLogsService.CreateEvent()
      parameters:
        - key: options
          type: CreateAuditLogEventOptions
          expanded: true
          properties:
            - key: OrganizationId
              type: string
              description: (create_event.organization_id)
            - key: Event
              type: AuditLogEvent
              expanded: true
              properties:
                - key: Action
                  type: string
                  description: (create_event.action)
                - key: OccurredAt
                  type: DateTime
                  description: (create_event.occurred_at)
                - key: Version
                  type: int
                  optional: true
                  description: (create_event.version)
                - key: Actor
                  type: AuditLogEventActor
                  expanded: true
                  properties:
                    - key: Type
                      type: string
                      description: (create_event.actor.type)
                    - key: Id
                      type: string
                      description: (create_event.actor.id)
                    - key: Name
                      type: string
                      optional: true
                      description: (create_event.actor.name)
                    - key: Metadata
                      type: 'Dictionary<string, string>'
                      optional: true
                      description: (create_event.metadata)
                - key: Targets
                  type: List<AuditLogEventTarget>
                  expanded: true
                  properties:
                    - key: Type
                      type: string
                      description: (create_event.target.type)
                    - key: Id
                      type: string
                      description: (create_event.target.id)
                    - key: Name
                      type: string
                      optional: true
                      description: (create_event.target.name)
                    - key: Metadata
                      type: 'Dictionary<string, string>'
                      optional: true
                      description: (create_event.metadata)
                - key: Context
                  type: AuditLogEventContext
                  expanded: true
                  properties:
                    - key: Location
                      type: string
                      description: (create_event.context.location)
                    - key: UserAgent
                      type: string
                      optional: true
                      description: (create_event.context.user_agent)
                - key: Metadata
                  type: 'Dictionary<string, string>'
                  optional: true
                  description: (create_event.metadata)
        - key: idempotencyKey
          type: string
          optional: true
          description: (idempotency_key)
        - (cancellationToken)
  php:
    - key: createEvent
      id: create_event
      url: /reference/audit-logs/create-event
      title: $auditLogs->createEvent()
      parameters:
        - key: organizationId
          type: string
          description: (create_event.organization_id)
        - key: event
          type: array
          expanded: true
          properties:
            - key: action
              type: string
              description: (create_event.action)
            - key: occurred_at
              type: string
              description: (create_event.occurred_at)
            - key: version
              type: number
              optional: true
              description: (create_event.version)
            - key: actor
              type: array
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.actor.type)
                - key: id
                  type: string
                  description: (create_event.actor.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: array
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: array
              expanded: true
              properties:
                - key: type
                  type: string
                  description: (create_event.target.type)
                - key: id
                  type: string
                  description: (create_event.target.id)
                - key: name
                  type: string
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: array
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: array
              expanded: true
              properties:
                - key: location
                  type: string
                  description: (create_event.context.location)
                - key: user_agent
                  type: string
                  description: (create_event.context.user_agent)
                  optional: true
            - key: metadata
              type: array
              optional: true
              description: (create_event.metadata)
        - key: idempotencyKey
          type: string
          optional: true
          description: (idempotency_key)
  python:
    - key: create_event
      id: create_event
      url: /reference/audit-logs/create-event
      title: audit_logs.create_event()
      parameters:
        - key: organization_id
          type: str
          description: (create_event.organization_id)
        - key: event
          type: AuditLogEvent
          expanded: true
          properties:
            - key: action
              type: str
              description: (create_event.action)
            - key: occurred_at
              type: datetime
              description: (create_event.occurred_at)
            - key: version
              type: int
              optional: true
              description: (create_event.version)
            - key: actor
              type: AuditLogEventActor
              expanded: true
              properties:
                - key: type
                  type: str
                  description: (create_event.actor.type)
                - key: id
                  type: str
                  description: (create_event.actor.id)
                - key: name
                  type: str
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: dict
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: 'Sequence[AuditLogEventTarget]'
              expanded: true
              properties:
                - key: type
                  type: str
                  description: (create_event.target.type)
                - key: id
                  type: str
                  description: (create_event.target.id)
                - key: name
                  type: str
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: dict
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: AuditLogEventContext
              expanded: true
              properties:
                - key: location
                  type: str
                  description: (create_event.context.location)
                - key: user_agent
                  type: str
                  optional: true
                  description: (create_event.context.user_agent)
            - key: metadata
              type: dict
              optional: true
              description: (create_event.metadata)
        - key: idempotencyKey
          type: str
          optional: true
          description: (idempotency_key)
  ruby:
    - key: create_event
      id: create_event
      url: /reference/audit-logs/create-event
      title: AuditLogs.create_event()
      parameters:
        - key: organization
          type: String
          description: (create_event.organization_id)
        - key: event
          type: Hash
          expanded: true
          properties:
            - key: action
              type: String
              description: (create_event.action)
            - key: occurred_at
              type: String
              description: (create_event.occurred_at)
            - key: version
              type: Integer
              optional: true
              description: (create_event.version)
            - key: actor
              type: Hash
              expanded: true
              properties:
                - key: type
                  type: String
                  description: (create_event.actor.type)
                - key: id
                  type: String
                  description: (create_event.actor.id)
                - key: name
                  type: String
                  optional: true
                  description: (create_event.actor.name)
                - key: metadata
                  type: Hash
                  optional: true
                  description: (create_event.metadata)
            - key: targets
              type: 'Array[Hash]'
              expanded: true
              properties:
                - key: type
                  type: String
                  description: (create_event.target.type)
                - key: id
                  type: String
                  description: (create_event.target.id)
                - key: name
                  type: String
                  optional: true
                  description: (create_event.target.name)
                - key: metadata
                  type: Hash
                  optional: true
                  description: (create_event.metadata)
            - key: context
              type: Hash
              expanded: true
              properties:
                - key: location
                  type: String
                  description: (create_event.context.location)
                - key: user_agent
                  type: String
                  optional: true
                  description: (create_event.context.user_agent)
            - key: metadata
              type: Hash
              optional: true
              description: (create_event.metadata)
        - key: idempotency_key
          type: String
          optional: true
          description: (idempotency_key)
  go:
    - key: CreateEvent
      id: create_event
      url: /reference/audit-logs/create-event
      title: auditlogs.CreateEvent()
      parameters:
        - (ctx)
        - key: opts
          type: auditlogs.CreateEventOpts
          expanded: true
          properties:
            - key: OrganizationID
              type: string
              description: (create_event.organization_id)
            - key: Event
              type: auditlogs.Event
              expanded: true
              properties:
                - key: Action
                  type: string
                  description: (create_event.action)
                - key: OccurredAt
                  type: time.Time
                  description: (create_event.occurred_at)
                - key: Version
                  type: int
                  optional: true
                  description: (create_event.version)
                - key: Actor
                  type: auditlogs.Actor
                  expanded: true
                  properties:
                    - key: Type
                      type: string
                      description: (create_event.actor.type)
                    - key: ID
                      type: string
                      description: (create_event.actor.id)
                    - key: Name
                      type: string
                      optional: true
                      description: (create_event.actor.name)
                    - key: Metadata
                      type: 'map[string]interface{}'
                      optional: true
                      description: (create_event.metadata)
                - key: Targets
                  type: '[]auditlogs.Target'
                  expanded: true
                  properties:
                    - key: Type
                      type: string
                      description: (create_event.target.type)
                    - key: ID
                      type: string
                      description: (create_event.target.id)
                    - key: Name
                      type: string
                      optional: true
                      description: (create_event.target.name)
                    - key: Metadata
                      type: 'map[string]interface{}'
                      optional: true
                      description: (create_event.metadata)
                - key: Context
                  type: auditlogs.Context
                  expanded: true
                  properties:
                    - key: Location
                      type: string
                      description: (create_event.context.location)
                    - key: UserAgent
                      type: string
                      optional: true
                      description: (create_event.context.user_agent)
                - key: Metadata
                  type: 'map[string]interface{}'
                  optional: true
                  description: (create_event.metadata)
            - key: IdempotencyKey
              type: string
              optional: true
              description: (idempotency_key)
      returns:
        - (err)
originalPath: .tmp-workos-clone/packages/docs/content/reference/audit-logs/event/create.mdx
---

## Create Event

Create an Audit Log Event.

This API supports idempotency which guarantees that performing the same operation multiple times will have the same result as if the operation were performed only once. This is handy in situations where you may need to retry a request due to a failure or prevent accidental duplicate requests from creating more than one resource.

To achieve idempotency, you can add `Idempotency-Key` request header to a Create Event request with a unique string as the value. Each subsequent request matching this unique string will return the same response. We suggest using [v4 UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier) for idempotency keys to avoid collisions.

Idempotency keys expire after 24 hours. The API will generate a new response if you submit a request with an expired key.

<CodeBlock
  title="Request"
  referenceId="create_event"
  file="create-event-request"
/>
