MrRefactoring / jira.js

A JavaScript/TypeScript wrapper for the JIRA Cloud, Service Desk and Agile REST API
https://mrrefactoring.github.io/jira.js/
MIT License
349 stars 46 forks source link

Q: how to create issue with custom fields #302

Closed marcelstoer closed 3 months ago

marcelstoer commented 3 months ago

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.

MrRefactoring commented 3 months ago

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');
};
marcelstoer commented 3 months ago

Thanks.