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

# Webhook を使ったチケットの自動解決

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="Webhook を利用したチケットの自動解決" description="オンプレミス環境や未対応のチケット管理システムを、Webhook-to-session ブリッジで Devin に接続します。" prompt="私のチケット管理システム向けに、Webhook-to-Devin パイプラインのセットアップを手伝ってください。https://docs.devin.ai/use-cases/gallery/api-webhook-custom-ticketing にあるガイドに従い、サービスユーザーの作成、Webhook ハンドラーの構築、そしてチケット管理システムを設定してイベントをそのハンドラーに送信するまで、各ステップを順番に案内してください。" category="自動化" features="API、Playbooks" />

<div className="uc-detail-wrapper">
  <Tip>手動でのセットアップを省略したい場合は、このページのリンクを Devin のセッションに貼り付けて、すべてのセットアップを依頼してください。</Tip>

  <Steps>
    <Step title="サービスユーザーを作成">
      Devin は API 呼び出しを認証するために [service user tokens](/ja/api-reference/v3/overview) を使用します。これは本番環境の自動化に推奨される方法です。

      1. [app.devin.ai](https://app.devin.ai/?utm_source=docs\&utm_medium=use-case-gallery) > **Settings** > **Service Users** に移動し、`ManageOrgSessions` 権限を持つ新しい service user を作成します
      2. 作成後に表示される API トークンをコピーして安全に保管します — このトークンは一度しか表示されず、webhook ハンドラ内で `DEVIN_API_KEY` として使用します

      組織 ID を確認するには、トークンを使用して `GET https://api.devin.ai/v3/enterprise/organizations` を呼び出します — この URL では org のスラッグのみが表示され、ID は表示されません。

      次の 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."}'
      ```

      `session_id` と `url` が返されます。Devin の Web アプリでテストセッションを削除して、次に進んでください。
    </Step>

    <Step title="Webhook ハンドラーを実装する">
      このパターンは、**オンプレミスのチケット管理システム** (セルフホスト型の Jira、Redmine、Bugzilla など) や、**ネイティブな Devin 連携を持たないチケット管理ツール** (組み込みサポートがある [Linear](/ja/integrations/linear) や [Jira Cloud](/ja/integrations/jira) とは異なる) に最適です。チケット管理システムが webhook をサポートしていれば、小さなサービスを挟むことで Devin と連携できます。

      プロンプト内にチケット管理システムの API ドキュメントへのリンクを含めておき、Devin がチケットにコメントを投稿し直す方法を理解できるようにします。チケット管理 API トークンは [session secret](/ja/api-reference/common-flows) として渡し、Devin が直接認証できるようにします。

      Devin にひな形の作成を依頼します:

      <PromptBlock>
        ```txt カスタムチケティング用の Webhook ハンドラー 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 playbook_id 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.
        ```
      </PromptBlock>

      コアとなるハンドラーは次のようになります:

      ```javascript theme={null}
      const PLAYBOOKS = {
        'devin-autofix': 'playbook-a1b2c3d4e5f6',
        'devin-feature': 'playbook-f6e5d4c3b2a1',
      };

      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 => PLAYBOOKS[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: [
              `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'),
            playbook_id: PLAYBOOKS[label],
            session_secrets: [
              { key: 'TICKET_API_TOKEN', value: process.env.TICKET_API_TOKEN },
            ],
          }),
        }).then(r => r.json());

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

      `PLAYBOOKS` マップは、チケットラベルを **Settings > Playbooks** で作成した[プレイブック](/ja/product-guides/creating-playbooks)に対応付けます。バグ修正用のプレイブックには *「必ず回帰テストを追加する」*、機能追加用のプレイブックには *「ドラフト PR を作成してレビューを依頼する」* といった内容を記載できます。

      プロンプトには、Devin がコメントを投稿する方法を理解できるように、利用しているチケットシステムの API ドキュメントへのリンクを含めます。`TICKET_API_TOKEN` は[セッションシークレット](/ja/api-reference/common-flows)として渡されます — そのセッションでのみ環境変数として注入され、保存されることはありません。API ドキュメントの URL を、実際に利用しているチケットシステムのドキュメントに置き換えてください。

      ハンドラーは HTTPS の POST リクエストを受け取れる任意の環境にデプロイします — クラウドファンクション (AWS Lambda、Google Cloud Functions) 、コンテナ、または VPS などです。その URL をチケットシステムの通知またはインテグレーション設定で webhook として登録し、**ticket created** イベントを対象にフィルタします。

      `devin-autofix` ラベル付きのテストチケットを作成し、フルループを検証します: チケット作成 → webhook 発火 → Devin セッション開始 → PR 作成 → Devin がチケットにコメントを投稿。
    </Step>
  </Steps>
</div>
