balintn
balintn

Reputation: 1433

Jira REST error "The value 'XXX' does not exist for the field 'project'."] while performing search with JQL

I'm trying to call a Jira REST API from .Net (query issues in a project), but I get the above HTTP 400 error.

This is how I make the call:

using System.Net;
var jiraRequest = HttpWebRequest.CreateHttp("https://example.com/rest/api/latest/search?jql=project=projectname");
jiraRequest.Credentials = new NetworkCredential(username, password);
var response = (HttpWebResponse)jiraRequest.GetResponse();

As I was debugging it, a noticed that requesting the same URL from Chrome works, but from IE it doesn't. Any ideas?

Upvotes: 2

Views: 9595

Answers (6)

Гадость
Гадость

Reputation: 1

The final and undisputable decision is set header Authorization: Basic <your api key>, api key you can create in "manage profile--->security---> create token", if it doesn't work, input your email and api token in basic auth setting in postman, than copy encrypted token from header Authorization with "Basic" word in the beginning

Upvotes: 0

kib gabriel
kib gabriel

Reputation: 138

Try using basic auth (username and password) with email as username and your api token as password. Create the API token in Jira Account-> Security settings

Upvotes: 0

zpea
zpea

Reputation: 1082

The error occurs if the user performing the JQL search lacks the browse project permission on the project 'XXX'. Without that permission Jira treats the project as non-existant, so it is not a valid filter value.

That it worked for you in Chrome, but not in IE or using your code, might be because you had been logged in as different users (e.g. your personal account, a bot user, anonymous/not logged in).

Upvotes: 1

Alongkorn
Alongkorn

Reputation: 4207

you should find the root cause first by trying with standard curl

curl -D- -u USER:PASSWORD -X GET -H "Content-Type: application/json" URL

if it works fine, it means that your code is incorrect.

try to see the headers of your code, it must have Authorization: Basic xxxx

Upvotes: 0

Brent Washburne
Brent Washburne

Reputation: 13158

That error message is misleading. The problem is with the authorization credentials. My code was sending this HTTP header:

Authorization: Token blablabla

When I changed the header to the correct form, it worked:

Authorization: Basic blablabla

Upvotes: 0

rorschach
rorschach

Reputation: 2947

JQL strings can be quite complex and having them properly encoded as parameters in a GET request might become a headache. I recommend you instead switch to the POST endpoint for /search.

Upvotes: 0

Related Questions