Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

API: How to return no fields?

Christopher Marriott
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 20, 2024

I have a point in my code where I want to get an issue's id given it's key.

I'm successfully using the `/issue/{key}` endpoint to do so, but wondered if there was a way to prevent all fields from being returned. I have no need for them in this case.

I've tried passing in a empty string to the "field" param, but it falls back to the default (all fields).

For now I've restricted it to just returning the summary field, but it feels like there should be a way to not have any fields return at all.

Is there such a way?

1 answer

1 accepted

6 votes
Answer accepted
Michel Neeser
Community Champion
May 20, 2024

Hi @Christopher Marriott and welcome!

If you pass an invalid value to the fields param, then no fields will be returned at all. You could pass an "x", for example:

?fields=x

But please keep in mind that this is an undocumented "feature" and therefore not guaranteed to work forever. Best practice would be to include the summary field as you mentioned, and then simply ignore this field in your code, as the overhead of one field is negligible.

Matt Doar _Adaptavist_
Community Champion
May 20, 2024

I never realized that, cool. I only ever managed to get the set of fields down to the required system fields of summary, issue type and reporter. And status I guess

Like Michel Neeser likes this
Sunny Ape
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2024

Also, you could force the endpoint to return only the ID field by declaring only it:

?fields=id

...but you still get back other, non-excludable response objects such as expand, self and key,

If you want to be sneaky and get just the issueId value and no other objects in the response, use the Search Issue IDs using JQL endpoint and search for just one issue key:

POST:

{{Instance}}/rest/api/3/search/id

Body:

{
"jql": "key = ABC-123"
}

Response:

{
"issueIds": [
10001
]
}

 

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events