Triggering Actions via API

Custom Actions Trigger API

OpsLevel’s GraphQL API lets you list available triggers for Custom Actions, invoke them programmatically, and poll their status.


1. List Trigger Definitions

Fetch all Custom Action trigger definitions available in your account.

query GetCustomActionsTriggerDefinitions {
  account {
    customActionsTriggerDefinitions {
      totalCount             # Total number of trigger definitions
      nodes {
        __typename           # GraphQL type name (CustomActionsTriggerDefinition)
        id                   # Globally-unique ID for the trigger
        name                 # Human-readable name
        entityType           # Entity the trigger applies to (e.g. "Service")
      }
    }
  }
}

Response fields:

FieldTypeDescription
totalCountIntCount of trigger definitions
nodes[].__typenameStringGraphQL type (always CustomActionsTriggerDefinition)
nodes[].idIDTrigger definition ID
nodes[].nameStringTrigger definition name
nodes[].entityTypeStringEntity type (e.g. Service, Account)

2. Invoke a Trigger

Invoke a Custom Action by its trigger definition ID. You can optionally pass a targetObject (e.g. a Service ID) and a JSON‐encoded manualInputs object.

mutation InvokeCustomAction(
  $triggerDefinitionId: ID!
  $targetObject: IdentifierInput
  $manualInputs: JSON
) {
  customActionsTriggerInvoke(
    input: {
      triggerDefinition: { id: $triggerDefinitionId }
      targetObject: $targetObject
      manualInputs: $manualInputs
    }
  ) {
    triggerEvent {
      ...TriggerEventFragment
      __typename
    }
    errors {
      message
      path
      __typename
    }
    __typename
  }
}

fragment TriggerEventFragment on CustomActionsTriggerEvent {
  id                      # ID of the created trigger event
  status                  # Current status: PENDING, PENDING_APPROVAL, SUCCESS, FAILURE
  definition {
    name                  # Name of the trigger definition
    owner {
      id
      name
      href
      __typename
    }
    __typename
  }
}

Input Arguments

VariableTypeDescription
triggerDefinitionIdID!ID of the trigger definition to invoke
targetObjectIdentifierInput(Optional) ID of the resource to associate in the form {id: Z2lkOi8vb3BzbG...."} (e.g. a Service)
manualInputsJSON(Optional) Key/value map of inputs defined in your action’s manual‐inputs schema

Payload

FieldTypeDescription
triggerEventCustomActionsTriggerEventNewly created event; see TriggerEventFragment
errors[]{ message, path, __typename }Validation or execution errors encountered when enqueueing the action trigger

3. Poll Trigger Event Status

After invoking, you can poll the event to check progress or final outcome:

query GetCustomActionTriggerEvent($eventId: ID!) {
  account {
    customActionsTriggerEvent(id: $eventId) {
      id        # Event ID
      status    # One of: PENDING, PENDING_APPROVAL, SUCCESS, FAILURE
    }
  }
}

Input Arguments

VariableTypeDescription
eventIdID!ID returned in triggerEvent.id

Response

FieldTypeDescription
idIDThe trigger event’s unique identifier
statusStringCurrent status (e.g. SUCCESS, FAILURE)

Status Workflow

  1. PENDING: The trigger has been accepted.
  2. PENDING_APPROVAL: The action is waiting for an approval before it executes.
  3. SUCCESS: Webhook returned a 2xx status.
  4. FAILURE: Non-2xx response or execution failure.

Use the id from the invocation response to poll until you reach SUCCESS or FAILURE.


Read more about configuring manual inputs → Manual Inputs Guide

Action Permissions

API tokens can run any custom action you have created because they are considered to be Administrators

User unavailable in Action Context

You cannot use the user object in liquid templates that are part of an action you invoke via API.

If you require information about a user that has triggered an action via API, you can include it as part of a Manual Input