Option 1: Node.js (with node-fetch or axios)

1. Install dependencies

npm install axios dotenv

2. Create .env file (optional for security)

LINEAR_API_KEY=your_linear_api_key_here
LINEAR_TEAM_ID=your_linear_team_id_here

3. createIssue.js

require('dotenv').config();
const axios = require('axios');

const LINEAR_API_URL = 'https://api.linear.app/graphql';

async function createLinearIssue(title, description) {
  const query = `
    mutation {
      issueCreate(
        input: {
          teamId: "${process.env.LINEAR_TEAM_ID}",
          title: "${title}",
          description: "${description}"
        }
      ) {
        success
        issue {
          id
          identifier
          url
        }
      }
    }
  `;

  try {
    const response = await axios.post(
      LINEAR_API_URL,
      { query },
      {
        headers: {
          Authorization: `Bearer ${process.env.LINEAR_API_KEY}`,
          'Content-Type': 'application/json',
        },
      }
    );

    if (response.data.data.issueCreate.success) {
      return response.data.data.issueCreate.issue.url;
    } else {
      console.error('Failed to create issue:', response.data);
    }
  } catch (error) {
    console.error('API error:', error.response?.data || error.message);
  }
}

// Example call
createLinearIssue('Test issue from API', 'Description goes here')
  .then((url) => console.log('Created issue at:', url));

Last updated