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

# Auto-Fix Tickets via Webhooks

> Connect a custom ticketing system to Devin with a webhook handler that calls the Devin API to start a session for each new bug ticket.

# Auto-Fix Tickets via Webhooks

Connect on-prem or unsupported ticketing systems to Devin with a webhook-to-session bridge.

Try in Devin ↗

Author
Cognition

Category
Automations

> [!TIP]
>
> Don't want to set this up manually? Paste a link to this page into a Devin session and ask it to set everything up for you.

**1. Create a service user**

Devin uses [service user tokens](https://docs.devinenterprise.com/api-reference/v3/overview.md) to authenticate API calls. This is the recommended approach for production automation.

1. Go to [app.devin.ai](https://app.devin.ai/?utm_source=docs\&utm_medium=use-case-gallery) > **Settings** > **Devin API** > **Service users** and create a new service user with a role that includes the **Use Devin sessions** (`UseDevinSessions`) permission — creating sessions requires this permission, and `ManageOrgSessions` alone does not grant it
2. Copy the API token shown after creation and store it securely — it's only displayed once and you'll use it as `DEVIN_API_KEY` in your webhook handler

Your organization ID is shown at the top of the **Settings** > **Devin API** page — the URL only shows the org slug, not the ID.

Test it with a quick curl:

```bash theme={null}
curl -X POST https://api.devin.ai/v3/organizations/YOUR_ORG_ID/sessions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Say hello — this is a test session."}'
```

You should get back a `session_id` and `url`. Delete the test session in the Devin web app and move on.

**2. Build the webhook handler**

This pattern is ideal for **on-prem ticketing systems** (like self-hosted Jira, Redmine, or Bugzilla) or **ticketing tools that don't have a native Devin integration** (unlike [Linear](https://docs.devinenterprise.com/integrations/linear.md) and [Jira Cloud](https://docs.devinenterprise.com/integrations/jira.md), which have built-in support). If your ticketing system supports webhooks, you can bridge it to Devin with a small service.

Include a link to your ticketing system's API documentation in the prompt so Devin can figure out how to post comments back to tickets. Pass the ticketing API token as a [session secret](https://docs.devinenterprise.com/api-reference/common-flows.md) so Devin can authenticate directly.

Ask Devin to scaffold it:

```txt Webhook handler for custom ticketing theme={null}
Build an Express.js service that:
1. Accepts POST /webhooks/tickets with a JSON body containing id, title,
   description, and labels
2. Verifies the webhook signature using HMAC-SHA256
3. Skips tickets without a "devin-autofix" or "devin-feature" label
4. Calls POST https://api.devin.ai/v3/organizations/{org_id}/sessions
   with a prompt built from the ticket fields, a skill mention based on
   the label, and the ticketing API token as a session secret

Read DEVIN_API_KEY, DEVIN_ORG_ID, TICKET_API_TOKEN, and WEBHOOK_SECRET
from environment variables.
```

Here's what the core handler looks like:

```javascript theme={null}
const SKILLS = {
  'devin-autofix': '@skills:fix-bug',
  'devin-feature': '@skills:build-feature',
};

app.post('/webhooks/tickets', async (req, res) => {
  if (!verifySignature(req)) return res.status(401).send('Bad signature');

  const { id, title, description, labels } = req.body;
  const label = labels.find(l => SKILLS[l]);
  if (!label) return res.status(200).send('No Devin label — skipped');

  const orgId = process.env.DEVIN_ORG_ID;
  const { session_id } = await fetch(
    `https://api.devin.ai/v3/organizations/${orgId}/sessions`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.DEVIN_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt: [
        SKILLS[label],
        `Ticket ${id}: ${title}`,
        description,
        `Reference ticket ${id} in your commit message.`,
        `When done, post a comment on ticket ${id} with a summary of your`,
        `changes and a link to the PR. Use the ticketing API at`,
        `https://your-ticketing-system.com/api/docs to post the comment.`,
        `Authenticate with the $TICKET_API_TOKEN environment variable.`,
      ].join('\n\n'),
      session_secrets: [
        { key: 'TICKET_API_TOKEN', value: process.env.TICKET_API_TOKEN },
      ],
    }),
  }).then(r => r.json());

  res.json({ session_id });
});
```

The `SKILLS` map routes ticket labels to [skills](https://docs.devinenterprise.com/product-guides/skills.md) you create on **Customize > Skills**; mentioning `@skills:<name>` at the top of the prompt runs that skill. A bug-fix skill might say *"Always add a regression test"*; a feature skill might say *"Create a draft PR and request review."*

The prompt includes a link to your ticketing system's API docs so Devin knows how to post comments back. The `TICKET_API_TOKEN` is passed as a [session secret](https://docs.devinenterprise.com/api-reference/common-flows.md) — it's injected as an environment variable for that session only and never stored. Replace the API docs URL with your actual ticketing system's documentation.

Deploy the handler anywhere that can receive HTTPS POST requests — a cloud function (AWS Lambda, Google Cloud Functions), a container, or a VPS. Register its URL as a webhook in your ticketing system's notification or integration settings, and filter for **ticket created** events.

Create a test ticket with the `devin-autofix` label to verify the full loop: ticket created → webhook fires → Devin session starts → PR opened → Devin posts a comment on the ticket.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.