MrRefactoring / jira.js

A JavaScript/TypeScript wrapper for the JIRA Cloud, Service Desk and Agile REST API

Home Page:https://mrrefactoring.github.io/jira.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Q: how to create issue with custom fields

marcelstoer opened this issue · comments

Looking at the CreateIssue interface I don't understand how I would pass custom fields when creating an issue.

https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-post shows that we should pass custom fields such as "customfield_10000" just like regular properties.

Please check this out how to create issue with custom fileds:

Screenshot 2024-03-22 at 17 44 38

Code snippet:

export const createIssue = async (client: Version3Client) => {
  const projects = await client.projects.getAllProjects();

  if (projects.length) {
    const { key } = projects[0];

    const { id } = await client.issues.createIssue({
      fields: {
        summary: 'My first issue',
        issuetype: {
          name: 'Task',
        },
        project: {
          key,
        },
        customfield_10000: 'value',
      },
    });

    return client.issues.getIssue({ issueIdOrKey: id });
  }

  throw new Error('First create a project');
};

Thanks.