> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Subscription

## Data Structure

### CreateWebhookSubscriptionInput

An input object for `WebhookSubscription` creation

| Parameter      | Type                   | Description                                                       |
| :------------- | :--------------------- | :---------------------------------------------------------------- |
| `label`        | `String`               | Optional webhook subscription record label.                       |
| `triggerEvent` | `WebhookTriggerEvent!` | An event ID that triggers this webhook.                           |
| `targetUrl`    | `String!`              | An endpoint URL where the webhook will be sent.                   |
| `signature`    | `String`               | Optional signature that could be used for payload authentication. |

## Mutations

### createWebhookSubscription

Creates a new webhook subscription for a given event type by CreateWebhookSubscriptionInput input object.
Once created, the subscription becomes active and will receive event payloads when the specified event is triggered.

<Info>
  * The API user context must have `AUTHENTICATED` scope to access webhook subscriptions. Anonymous users cannot retrieve this data.
  * The API user context must have permission to create webhook subscriptions.
  * The API user context must be present and valid - otherwise, access is denied.
</Info>

The following arguments can be used in the mutation:

| Argument | Type                              | Description                                     |
| :------- | :-------------------------------- | :---------------------------------------------- |
| `input`  | `CreateWebhookSubscriptionInput!` | Input data for creating a webhook subscription. |

<CodeGroup>
  ```graphql GraphQL Query theme={null}
  mutation createWebhookSubscription {
    createWebhookSubscription(input: {
      label: "User have complete a training",
      triggerEvent: USER_COMPLETED_TRAINING,
      targetUrl: "https://HOOKS_TARGET_ENDPOINT",
      signature: "MySecretSignature"
    }) {
      response {
        id
        label
        triggerEvent
        targetUrl
        status
      }
      errors
    }
  }
  ```

  ```json Response theme={null}
  {
    "createWebhookSubscription": {
      "response": {
        "id": "5",
        "label": "User have complete a training",
        "triggerEvent": "USER_COMPLETED_TRAINING",
        "targetUrl": "https://HOOKS_TARGET_ENDPOINT",
        "status": "SUBSCRIBED"
      },
      "errors": []
    }
  }
  ```
</CodeGroup>

## Related Features

The `createWebhookSubscription` mutation supports the same advanced features as other mutations:

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/OpignoEnterpriseAPI/ConsumerUserAuthentication">
    Understand the authentication requirements and how to properly authenticate your requests.
  </Card>
</CardGroup>

Common error scenarios and solutions:

<AccordionGroup>
  <Accordion title="Authentication Errors">
    * **401 Unauthorized**: Ensure you're using a valid authentication token with `AUTHENTICATED` scope
    * **403 Forbidden**: Verify your user account has the necessary permissions to access webhook subscription data
  </Accordion>
</AccordionGroup>
