Create Issue API for Custom Issue Type

Hi
We are using Forge platform. We have added new Issue Type and we are trying to create issue using this new Custom Issue Type. The issue create API error out saying “Specify Issue Type”. Have any one tried creating issue with custom issue type through API?

Thanks

Any representative from Atlassian?

Hi @sushilb,

I was able to successfully create a new issue using a new issue type I created.

Here are the steps I did in the UI:

  1. Created the new issue type in the Issue Type screen
  2. Associated the new issue type with an issue type scheme for project with key TEST and id 10000

To create the issue via API call:

  1. To ensure that I can create an issue in the specified project, I called Get create issue metadataGET /rest/api/3/issue/createmeta?projectKeys=TEST which gives me a response like this:
{
    "expand": "projects",
    "projects":
    [
        {
            "self": "https://iragudo.atlassian.net/rest/api/3/project/10000",
            "id": "10000",
            "key": "TEST",
            "name": "Test",
            "avatarUrls":
            {
                "48x48": "https://iragudo.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10413",
                "24x24": "https://iragudo.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10413?size=small",
                "16x16": "https://iragudo.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10413?size=xsmall",
                "32x32": "https://iragudo.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10413?size=medium"
            },
            "issuetypes":
            [
                {
                    "self": "https://iragudo.atlassian.net/rest/api/3/issuetype/10002",
                    "id": "10002",
                    "description": "A small, distinct piece of work.",
                    "iconUrl": "https://iragudo.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10318?size=medium",
                    "name": "Task",
                    "untranslatedName": "Task",
                    "subtask": false
                },
                 ...
                {
                    "self": "https://iragudo.atlassian.net/rest/api/3/issuetype/10016",
                    "id": "10016",
                    "description": "",
                    "iconUrl": "https://iragudo.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10300?size=medium",
                    "name": "Custom Ian Issue Type",
                    "untranslatedName": "Custom Ian Issue Type",
                    "subtask": false
                }
            ]
        }
    ]
}
  1. Now that I’m sure the issue type is associated with the project, I now call the Create issue API with this body:
{
  "fields": {
    "description": {
      "content": [
        {
          "content": [
            {
              "text": "This is created via API",
              "type": "text"
            }
          ],
          "type": "paragraph"
        }
      ],
      "type": "doc",
      "version": 1
    },
    "issuetype": {
      "id": "10016"
    },
    "labels": [
      "test"
    ],
    "project": {
      "id": "10000"
    },
    "summary": "API TEST Custom Issue Type"
  },
  "update": {}
}

With the above-mentioned steps, I was able to successfully create an issue.

Can you share your Create issue REST API call’s request body so we can verify that the necessary issue type field was supplied?

Hope this helps,
Ian

2 Likes

@ianRagudo
Thanks a lot for your help. Yes, we supplied issuetype Name not id. Do you think issue type name instead of id should work?

Hi @sushilb,

Yes, supplying the issue type name will work and the request body will look something like this (same as above but using name instead of id):

{
  "fields": {
    ...
    "issuetype": {
      "name": "Custom Ian Issue Type"
    } 
   }
}

What does your request body look like?

Ian

Here is the code

const createTestCase = async (testCases = []) => {
    for (let i = 0; i < testCases.length; i++) {
      const currTestCase = testCases[i];
      const testCasesField = {
        project: {
          key: projectKey,
        },
        issuetype: {
          name: "Test Case",
        },
        parent: { key: issueKey },
        summary: `${currTestCase.title}`,
        description: {
          type: "doc",
          version: 1,
          content: [
            {
              content: [
                {
                  type: "text",
                  text: "Test Case",
                  marks: [
                    {
                      type: "strong",
                    },
                  ],
                },
              ],
              type: "paragraph",
            },
            {
              content: [
                {
                  text: currTestCase.testCase,
                  type: "text",
                },
              ],
              type: "paragraph",
            },
          ],
        },
      };

      const createdTestCase = await createIssue(testCasesField);

      console.info(
        `Test Case :: issueKey=${issueKey} Iteration=${i}  createdIssue=${JSON.stringify(
          createdTestCase
        )}`
      );
    }
  };


const createIssue = async (issueFields) => {
    const createdIssue = await api
      .asApp()
      .requestJira(route`/rest/api/3/issue`, {
        method: "POST",
        body: JSON.stringify({ fields: issueFields }),
      })
      .then((response) => {
        return response.json();
      });

    return createdIssue;
  };
  await handleGenerateJiraStory();

  return {
    body: "Success",
    statusCode: 200,
  };
};

It gives error saying “Specify Issue Type”. So primarily I think it’s not recognizing the issue type.

Hi @sushilb,

I ran your code snippet (removed the loop but the issue creation logic remains intact) and it works fine for me. Have you tried calling Get create issue metadata for your project given your projectKey? It is possible that your custom issue type “Test Case” is not associated with the project.

Based on recent verification, supplying the issue type name in Create issue REST API works as expected.

Cheers,
Ian

1 Like

@ianRagudo Yes, we got it working. Thanks for your help, really appreciate it. I think when the project is team managed the global Issue Type does not get propogated and it was not creating it :(. Now we ran into another issue of linking issues. But I will create as separate questions. Thanks again.

1 Like