Can you query the API using REST by custom field?

morenafiore November 12, 2012

8 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

9 votes
Answer accepted
James Wood December 30, 2012

Hi Jim

I was having the same issues and this is how I worked it out just now.

Instead of having customfield_10020=xxxx, change it to cf[10020]=xxxx

Hope this works for you

chamiranga February 19, 2014

Thanks for your answer James. It worked for me.

this is what I used:

<my url>/rest/api/2/search?jql=cf[10020]~xxxxxxx

for curl :
curl -D- -u USERNAME:PWD -X GET -H "Content-Type: application/json" -g <my url>/rest/api/2/search?jql=cf[10020]~xxxxxxx

Thanks :)

4 votes
Faisal
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.
November 12, 2012

Hi Morena,

From the provided URL, I understand that you would like to retrieve search result by using REST API, can you kindly confirm this? Anyway, you mentioned that you are getting the same results when using different values, may I know what results are you getting?

Anyway I did a quick test on my end, and I am able to retrieve a search result by running the following cURL command in the Terminal:
- curl -D- -u admin:admin -X GET -H "Content-Type: application/json" http://localhost:8080/jira/rest/api/latest/search?jql=project=PG+AND+test~"test"
-- test is a custom field in JIRA

Therefore, can you kindly try to apply the GET request as per suggested above, and see if it helps? You may need to change the project key and the custom field name/values as well.

Cheers.

1 vote
James Wood December 30, 2012

Hi Jim

I was having the same issues and this is how I worked it out just now.

Instead of having customfield_10020=xxxx, change it to cf[10020]=xxxx

Hope this works for you

0 votes
akhil raja December 25, 2017

Hi 

 

i am facing the same issue i had tried using "cf[14729]=AA: Analytics"

but not working, it is showing


"errorMessages": [
"Error in the JQL Query: Expecting either 'OR' or 'AND' but got 'Analytics'. (line 1, character 90)"
],
"errors": {}

could anyone please suggest some solution on how to use customfields in querying

0 votes
morenafiore December 30, 2012

Hi Ahmad thank you so much for the answer.

I think I have solved the problem

Morena

Jim Thomson December 30, 2012

Could you include your resolution, as I'm having the same problem.

My CURL query results in all fields of all issues being returned.

Thanks,

Jim

0 votes
Faisal
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.
December 30, 2012

Hi Morena, Jim,

Apology for the delay here. The error that you are getting when running the query:

I get the error "Field 'customfield_10020' does not exist or you do not have permission to view it.'. Please note the field's context is global and for all issue types.

This indicates that either the custom field with the ID 10020 does not exists, or the field itself is not applicable to the project OEWR. Since this is the case, things that I would like to check is:
- Confirm if the field with the ID 10020 exists: We can check this from the database level, using the following query:

select * from customfield where id=10020

You may also confirm the field name and field type from the results returned.

- Check the custom field configuration and confirm if the field is configured to be applicable to global context and all issue types
You can go to Administration > Custom Fields > Go to the field, and click on Configure > Edit Configuration. Check the custom field applicable issue types and applicable context and ensure that both are configured to 'Any issue type' and Global Context respectively

I hope that this will help, let us know how it goes.

Thanks.

akhil raja December 25, 2017

Hi Ahmad

 

can you please say me where i can configure the custom-field setting could you brief me as i am new to work on this tool

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 26, 2017

Please see the accepted answer, but bear in mind it is 5 years old.

0 votes
Jim Thomson December 30, 2012

Did you find a resolution to this? I'm having the same problem.

morenafiore January 2, 2013

do you still have the problem? if so can you paste your code and add a link if you can?

0 votes
Faisal
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.
November 12, 2012

Hi Morena,

Perhaps the following documentation on performing searches using REST may help:
- https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Query+issues

Thanks

morenafiore November 13, 2012

Unfortunately that does not answer my question.

I am using the REST API with PHP. So I need to retrieve all the issues which are part of a project(OEWR) and where the custom field called customfield_10020 is equal to an email address.

So if I try this query

https://morenafiore.atlassian.net/rest/api/latest/search?jql=customfield_10020=danandmorena\u0040gmail\u002ecom&fields=created,issuetype,status,summary
I get the error "Field 'customfield_10020' does not exist or you do not have permission to view it.'. Please note the field's context is global and for all issue types.
 
If I add the project type to the query then the call return ALL ISSUES, which is wrong, no issues have "danandmorena@gmail.com" as value for field customfield_10020
https://morenafiore.atlassian.net/rest/api/latest/search?jql=project=OEWR&customfield_10020=danandmorena\u0040gmail\u002ecom&fields=created,issuetype,status,summary
 
I also tried with CURL, this request should not retrieve 13 results, but 0
curl -D- -u morena:mypassword -X GET -H "Content-Type: application/json" https://morenafiore.atlassian.net/rest/api/latest/search?jql=project=OEWR&customfield_10020=danandmorena@gmail.com&fields=created,issuetype,status,summary
 
So what's going wrong here? Is it a bug within the API?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question