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?

Hi @dmorrow,

Can you please help me with that?

i am running into the same issue - any idea how to solve it?

Hi @florian,

Unfortunately, the @dmorrow never respond to me…
I still haven’t found a way to upload an avatar.

I am not sure about this but I think you might need to use a relative url, i.e. ./assets/my_image.png but you might also need to use a filestream from a local file rather than an online path after all