REST request for creating an Issue does not work for SCRUM project

Hi,

I would like to create a JIRA issue from within an forge app. It does work for Kanban projects, but not for SCRUM projects. There I get the following error:

{
	"errorMessages": [],
	"errors": {
		"summary": "Field 'summary' cannot be set. It is not on the appropriate screen, or unknown.",
		"description": "Field 'description' cannot be set. It is not on the appropriate screen, or unknown.",
		"labels": "Field 'labels' cannot be set. It is not on the appropriate screen, or unknown."
	}
}

The request itself is simple - I would say - and does not use any custom fields or ids:

	var bodyData = {
	"fields": {
	  "summary": "Test",
	  "project": {
		"key": context.platformContext.projectKey
	  },
	  "issuetype": {
		"name": "Story"
	  },
	  "description": {
		"type": "doc",
		"version": 1,
		"content": [
		  {
			"type": "paragraph",
			"content": [
			  {
				"text": "Test description",
				"type": "text"
			  }
			]
		  }
		]
	  },
	  "labels": [
		"testlabel"
	  ]
	}
  };
		
  const response = await api.asApp().requestJira(route`/rest/api/3/issue`, {
	method: 'POST',
	headers: {
	  'Accept': 'application/json',
	  'Content-Type': 'application/json'
	},
	body: JSON.stringify(bodyData)
  });

I created a GitHub repro to reproduce the error easier: SvenLauterbach/BugDemoAtlassianForge (github.com). #codegeist

Hope this is enough.

Thanks
Sven

Hey @SvenLauterbach,

This is likely to do with your issue configuration. Do those fields exist on the specified issue type?

Hi @danielwinterw

Thank you for your quick answer. I didnā€˜t change anything in my JIRA, itā€™s the plain vanilla Setup. When I create a Story in the Scrum project with the UI, the form contains those exact fields. I even did a REST query for the issue I created with the UI and the REST response does also contain those fields (like I entered them in the UI).

Maybe I will add some Screenshots later when Iā€˜m back at my Laptop.

Kind regards
Sven

Hi @danielwinterw ,

see the screenshot from the edit form:

And from the Project Settings:

I could also post the REST response of the GET request, if needed.

What about to change issuetype.name to issuetype.id in the request? Proper issuetype.id has to be found e.g. from GET /rest/api/3/project/{projectIdOrKey}?expand=issueTypes

Hi @OndejMedek ,

I tried it, but it didnā€™t work either. In the ā€œKanbanā€ project ā€œstoryā€ issue type has Id 1001 and in the ā€œScrumā€ project it has the Id 1005. I updated my demo project with:

const projectKey = context.platformContext.projectKey;

    const responseGetProject = await api.asApp().requestJira(route`/rest/api/3/project/${projectKey}?expand=issueTypes`, {
      headers: {
        'Accept': 'application/json'
      }
    });

    const jsonGetProject = await responseGetProject.json();

    const issueType = jsonGetProject.issueTypes.find(issueType => issueType.name == "Story");

    var bodyData = {
      "fields": {
        "summary": "Test",
        "project": {
          "key": projectKey
        },
        "issuetype": {
          "id": issueType.id
        },
        "description": {
          "type": "doc",
          "version": 1,
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "text": "Test description",
                  "type": "text"
                }
              ]
            }
          ]
        },
        "labels": [
          "testlabel"
        ]
      }
    };

    const response = await api.asApp().requestJira(route`/rest/api/3/issue`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(bodyData)
    });

If I query a issue which was created via UI, I receive the following JSON response, which does also contain the 3 fields:

{
	"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations,customfield_10010.requestTypePractice",
	"id": "10013",
	"self": "replaced",
	"key": "COD-1",
	"fields": {
		"statuscategorychangedate": "2021-09-11T21:18:12.052+0000",
		"issuetype": {
			"self": "replaced",
			"id": "10005",
			"description": "Stories track functionality or features expressed as user goals.",
			"iconUrl": "replaced",
			"name": "Story",
			"subtask": false,
			"avatarId": 10315,
			"entityId": "a4aacffa-7c0e-404b-b3e1-f384bd12024f",
			"hierarchyLevel": 0
		},
		"timespent": null,
		"project": {
			"self": "replaced",
			"id": "10001",
			"key": "COD",
			"name": "Codegeist2021",
			"projectTypeKey": "software",
			"simplified": true,
			"avatarUrls": {
				"48x48": "replaced",
				"24x24": "replaced",
				"16x16": "replaced",
				"32x32": "replaced"
			}
		},
		"fixVersions": [],
		"aggregatetimespent": null,
		"resolution": null,
		"customfield_10027": null,
		"customfield_10028": null,
		"customfield_10029": null,
		"resolutiondate": null,
		"workratio": -1,
		"issuerestriction": {
			"issuerestrictions": {},
			"shouldDisplay": false
		},
		"lastViewed": null,
		"watches": {
			"self": "replaced",
			"watchCount": 1,
			"isWatching": false
		},
		"created": "2021-09-11T21:18:11.803+0000",
		"customfield_10020": null,
		"customfield_10021": null,
		"customfield_10022": null,
		"customfield_10023": null,
		"priority": {
			"self": "replaced",
			"iconUrl": "replaced",
			"name": "Medium",
			"id": "3"
		},
		"customfield_10024": null,
		"customfield_10025": null,
		"labels": [
			"technicaldebt"
		],
		"customfield_10026": [],
		"customfield_10016": null,
		"customfield_10017": null,
		"customfield_10018": {
			"hasEpicLinkFieldDependency": false,
			"showField": false,
			"nonEditableReason": {
				"reason": "PLUGIN_LICENSE_ERROR",
				"message": "The Parent Link is only available to Jira Premium users."
			}
		},
		"customfield_10019": "0|i0002v:",
		"aggregatetimeoriginalestimate": null,
		"timeestimate": null,
		"versions": [],
		"issuelinks": [],
		"assignee": null,
		"updated": "2021-09-11T21:46:17.938+0000",
		"status": {
			"self": "replaced",
			"description": "",
			"iconUrl": "replaced",
			"name": "To Do",
			"id": "10002",
			"statusCategory": {
				"self": "replaced",
				"id": 2,
				"key": "new",
				"colorName": "blue-gray",
				"name": "To Do"
			}
		},
		"components": [],
		"timeoriginalestimate": null,
		"description": {
			"version": 1,
			"type": "doc",
			"content": [
				{
					"type": "paragraph",
					"content": [
						{
							"type": "text",
							"text": "test"
						}
					]
				}
			]
		},
		"customfield_10010": null,
		"customfield_10014": null,
		"timetracking": {},
		"customfield_10015": null,
		"customfield_10005": null,
		"customfield_10006": null,
		"security": null,
		"customfield_10007": null,
		"customfield_10008": null,
		"aggregatetimeestimate": null,
		"customfield_10009": null,
		"attachment": [],
		"summary": "check",
		"creator": {
			"self": "replaced",
			"accountId": "557058:4f04523f-b8a2-47a7-9198-25c71fb7f924",
			"avatarUrls": {
				"48x48": "replaced",
				"24x24": "replaced",
				"16x16": "replaced",
				"32x32": "replaced"
			},
			"displayName": "Sven Lauterbach",
			"active": true,
			"timeZone": "Etc/GMT",
			"accountType": "atlassian"
		},
		"subtasks": [],
		"reporter": {
			"self": "replaced",
			"accountId": "557058:4f04523f-b8a2-47a7-9198-25c71fb7f924",
			"avatarUrls": {
				"48x48": "replaced",
				"24x24": "replaced",
				"16x16": "replaced",
				"32x32": "replaced"
			},
			"displayName": "Sven Lauterbach",
			"active": true,
			"timeZone": "Etc/GMT",
			"accountType": "atlassian"
		},
		"customfield_10000": "{}",
		"aggregateprogress": {
			"progress": 0,
			"total": 0
		},
		"customfield_10001": null,
		"customfield_10002": null,
		"customfield_10003": null,
		"customfield_10004": null,
		"environment": null,
		"duedate": null,
		"progress": {
			"progress": 0,
			"total": 0
		},
		"comment": {
			"comments": [],
			"self": "replaced",
			"maxResults": 0,
			"total": 0,
			"startAt": 0
		},
		"votes": {
			"self": "replaced",
			"votes": 0,
			"hasVoted": false
		},
		"worklog": {
			"startAt": 0,
			"maxResults": 20,
			"total": 0,
			"worklogs": []
		}
	}
}

So at this point I donā€™t know, what else I could try.

@OndejMedek @danielwinterw I found the reason for the issue: permissions.

When reading the documentation: https://developer.atlassian.com/platform/forge/runtime-reference/product-fetch-api/#authenticated-example

The asApp() function authenticates with the Atlassian products using a system user dedicated to your app. The system user is only a member of the default user group. This means the system user is not able to access private data such as Jira projects or Confluence spaces that are not visible to the default user group.

Iā€™ve checked the permissions in the SCRUM project:

With ā€œlimitedā€ is does not work, with ā€œopenā€ it does work. It is strange, that the default permissions of the ā€œKanbanā€ project does work.

Anyway, this means a Forge App needs to check if it has access or not and advice the user how to grant access.

1 Like

@SvenLauterbach rather than opening access, can you just add the asApp user to the proper permission? The user is the name of your app.

@danielwinterw I tried it already but I couldnā€™t find a user so I changed it to ā€œopenā€ in the Project access dropdown. To be honest, Iā€™m quite new to Atlassian Cloud JIRA, so I might have tried it the wrong way. I tried it by going to the project settings ā†’ Access ā†’ Add People. In the Dialog I couldnā€™t find something with the app name. I created a screen recording:

Animation

So, how can I add the app to the project?