How to upload avatar to a custom issue type

Hi,

I want to upload an image for a custom issue type that I’m creating in my Forge Custom UI app.
I’m using this endpoint in Jira API: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-types/#api-rest-api-3-issuetype-id-avatar2-post

In the official docs, I can’t find how to add the body of the request.

Anyone?
Seems like the Jira API docs are missing the actual file upload instructions…

Hi @amityahav ,

It looks like there’s a gap in our documentation as the code snippets don’t include a body parameter, however, it does include a curl example that has the parameter --data-binary "<@/path/to/file/with/your/avatar>". Since you asked this question in the context of Custom UI, could you try something like the following:

await api.asApp().requestJira(route`/rest/api/3/issuetype/{id}/avatar2?size={size}`, {
  method: 'POST',
  headers: {
    'Accept': 'application/json'
  },
  body: readStream // not sure where you intend to get your image from, but see https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams
});

Regards,
Dugald

Hi @dmorrow,

Thanks for getting back to me.

I’m trying a different approach now. I’m trying to set the avatar from the Forge part of the application (Under the ‘src’ directory).

This is what I’m trying to do:

const imageStreamResponse = await fetch( '/assets/my_image.png' );
	
	// Adding an avatar to the newly created issue type
	const response = await api.asApp().requestJira( route`/rest/api/3/issuetype/${ issueTypeId }/avatar2?size=24`, {
		method: 'POST',
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'image/png',
			'X-Atlassian-Token': 'no-check'
		},
		body: imageStreamResponse.body
	} );

But I’m getting this error:

ERROR   10:20:01.683  0e95aef6b6a31984  Invalid URL: /assets/my_image.png

I added this section in my manifest under ‘permissions’:

external:
    fetch:
      backend:
        - /assets/my_image.png

Any idea how to solve it? how can I upload a local image?