1

In jira I have a project called "Abc Def Management". When i tried to get all issues within this project Using rest Api, i am getting the following error.

errorMessages: [ 'Error in the JQL Query: The character \'%\' is a reserved JQL character. You must enclose it in a string or use the escape \'\\u0025\' instead.

I am entering my code below.

client.post("https://xxx.atlassian.net/rest/auth/1/session", loginArgs, function(data, response){
        console.log('Response', response);
        if (response.statusCode == 200) {
            console.log('succesfully logged in, session:', data.session);
            var session = data.session;
            // Get the session information and store it in a cookie in the header
            var searchArgs = {
                headers: {
                    // Set the cookie from the session information
                    cookie: session.name + '=' + session.value,
                    "Content-Type": "application/json"
                },
                data: {
                    // Provide additional data for the JIRA search. You can modify the JQL to search for whatever you want.
                    jql: "project=Abc%20Def%20Management"
                }
            };
            // Make the request return the search results, passing the header information including the cookie.
            client.post("https://xxx.atlassian.net/rest/api/2/search", searchArgs, function(searchResult, response) {
                console.log('status code:', response.statusCode);
                console.log('search result:', searchResult);
            });
            // response.render('index', {
            // });
        }
        else {
            console.log("Login failed");
            // throw "Login failed :(";
        }
    });

How can i resolve this error?

Hormis Lona
  • 503
  • 1
  • 8
  • 19

1 Answers1

1

Use spaces instead of %20.

You're using a POST request which will have the jql in its body, not as part of the url. So it is not necessary to url encode anything.

GlennV
  • 3,471
  • 4
  • 26
  • 39
  • I tried this also, but won't work. If the name of the project is a single word like 'abc' , then also it doesn't produce any result. – Hormis Lona Oct 03 '16 at 05:24
  • Does your jql return any results if you try it out in the jira issue search? – GlennV Oct 03 '16 at 06:10
  • 1
    @Appunni, you need to put the Project name in quotes, something like this: `jql = "Project=\"Abc Def Management\""` – rorschach Oct 03 '16 at 07:24
  • For more details about which characters need to be escaped in a json string, check this answer: http://stackoverflow.com/a/27516892/1453994 – GlennV Oct 03 '16 at 08:13
  • @GlennV yes i am getting result in jira issue search – Hormis Lona Oct 03 '16 at 10:18
  • @rorschach - tried this ...but getting error---- errorMessages: [ 'The value \'Abc Def Management\' does not exist for the field \'project\'.' – Hormis Lona Oct 03 '16 at 10:19
  • @Appunni are you sure that is the correct name of the Project? Maybe there are trailing whitespaces or something? It should work just like that. – rorschach Oct 03 '16 at 10:25
  • Does the user that you use to send the REST call have permission to view browse that project? If he does and the JQL works when you try it out with that same user in the issue search screen, then something is wrong with the authentication of your REST call. I'm not familiar with the client that you use, but I don't see any basic auth in your code either, so maybe that's what you're missing. – GlennV Oct 03 '16 at 10:27
  • @GlennV The variable 'loginArgs' contains the basic authentication values. Authentication is working correctly – Hormis Lona Oct 03 '16 at 10:45
  • @rorschach - yeah. am sure – Hormis Lona Oct 03 '16 at 10:46