Using node.js and Jira.js to create an issue

Viewed 40

I want to use node.js and Jira.js plugin to create a issue of type bug in Jira Cloud I have the authentication working

const client = new Version3Client({
    host: 'https://mysite.atlassian.net/',
    newErrorHandling: true,
    authentication: {
      basic: {
        email: 'myuser@gmail.com',
        apiToken: 'My token',
      },
    },
});

And I tested this

async function showAllProjects() {
    try {
      const data = await client.issues.getAllProjects();
      console.log('data', data);
    } catch (error) {
      console.log('error', error);
    }
  }
  
showAllProjects();

And is also working fine but I dont know how to pass the parameter to client.issues.createIssue to create the issue. Someone has an exmaple?

1 Answers

Try this out:

async function createIssue() {
  try {
    const issue = await client.issues.createIssue({
      fields: {
        summary: 'My first issue',
        issuetype: {
          name: 'Task'
        },
        project: {
          key: 'TEST',
        },
      }
    });
  } catch (e) {
    console.error(e);
  }
}

void createIssue();
Related