Can't copy description with attachments in postfunction

Hi, I have a post function which copies description from subtask to main issue when closing subtask and everything works perfectly fine until it contains attachments, then I get an error:

500 Internal Server Error: [{"errorMessages":["We couldn't save your changes. Copy your content, then try reloading the page."],"errors":{}}]

But when I send the same request authenticated as a user (who is also the author of these attachments), not as an addon, it works and description is copied with attachments as expected. How can I make it possible for addon?

I checked in Issues > Permission schemes that permission for attachments is already granted to atlassian-addons-project-access, but it doesn’t work anyway.

1 Like

With a 500 error it doesn’t sound like a permission error.

In the documentation for Adding an attachment (which I’m assuming you’re using) it has this note:

Note that:

  • The request must have a X-Atlassian-Token: no-check header, if not it is blocked. See Special headers for more information.
  • The name of the multipart/form-data parameter that contains the attachments must be file .

Also make sure your app has the write scope.

Thank you for reply. Actually I don’t add attachments via API - users add them when they add description. All I do from addon app is copying content of description and pasting it to main issue when subtask is being closed. If description contains attachment it looks like this in document format:

{
    "type" : "mediaGroup",
    "content" : [ {
      "type" : "media",
      "attrs" : {
        "id" : "4ce96d4d-e8cc-4ebb-94bb-7ba8136e5e86",
        "collection" : "jira-23947-field-description",
        "type" : "file",
        "occurrenceKey" : "347aafde-6b8c-4dc1-804e-e0a7e9e1e6b2"
      }
    } ]
}

And I can make a request updating main issue in two ways: using atlassianHostRestClients.authenticatedAsAddon() or atlassianHostRestClients.authenticatedAsHostActor(). In first case it doesn’t work if description contains attachments and in second case it works, but only if the user who closes subtask is also the person who added attachments. So it seems it is because of permissions, but I don’t know how to change them.
And my app already has the write scope.