[Jira, Forge] cherry pick fields and attributes when getting an issue via RES API

Hi everyone,

I have a Jira forge app, which defines a custom field in its manifest:

  jira:customField:
    - key: attachments-metadata
      name: AttachmentsMetadata
...

Currently, I’m getting the field’s value and the attachments via the following call:

await api
    .asApp()
    .requestJira(route`/rest/api/3/issue/${issueId}?expand=names`, {
    headers: {
      Accept: "application/json",
    },
  });

Then I look up the field’s name in the names array to get the issue id, an then I get the field’s value by id from the fields object. This is working great, but there’s too much data returned and I’m trying to optimise. I only want to get 2 things from the API:

  • the issue attachments;
  • the value of the above custom field;

How can I achieve this? I tried using the fields query param, but I don’t know the field id. I tried using the key from manifest fields=attachments-metadata&fieldsByKeys=true, but that didn’t work either. I’m also not able to get only the attachment property. Any ideas? Ideally, I wouldn’t have to make extra API calls as that defeats the purpose.

Hey @GeoSystems,

You can get the field ID by first making a call to the GET fields API. Note that you need only to make it once in your app’s lifetime: you can then save that ID for future use with the Storage API.

Thanks @kkercz - I’ll give it a go. I’ll still need to make a call to storage API on every subsequent request, right?

Also, is there a way to only get the custom field (assuming I know the id) and the attachment attribute without anything else?

I’ll still need to make a call to storage API on every subsequent request, right?

Yes, that’s correct.

Also, is there a way to only get the custom field (assuming I know the id) and the attachment attribute without anything else?

You can try the Jira expressions API with the following payload:

{
  "expression": "{ fieldValue: issue.customfield_1234, attachments: issue.attachments }",
  "context": {
    "issue": {
      "id": "issueId"
    }
  }
}

Otherwise, as you already noticed, using the fields expand parameter is the way to go for regular issue APIs.

1 Like

Thanks @kkercz - I’ll make some measurements as to which is faster - making 2 calls (to storage & API) or just one big API call, which returns all the data.