Making API Requests in spring boot connect app with jql query

Hi, I am following the tutorial:
https://bitbucket.org/atlassian/atlassian-connect-spring-boot/src/master/

I can now make an API request simply without search and jql queries like:

    @GetMapping(value = "/issue/{issueKey}")
    @ContextJwt
    @ResponseBody
    public String getIssueByIssueKey(@PathVariable String issueKey) throws JsonProcessingException {
        String preEncodedUriString = apiPrefix + "/issue/"+issueKey;
        UriComponents uriComponents = UriComponentsBuilder.fromUriString(preEncodedUriString).build(true);

        return atlassianHostRestClients.authenticatedAsAddon().getForObject(uriComponents.toUri(), String.class);
    }

However, it throws errors if I make an API request like /rest/api/3/search?jql=startAt=0&maxResults=100. I tried to convert all the = into %3D or the & into %26 or both but none of them works.

I found the [ACSPRING-150] - Ecosystem Jira in the tutorial above, however, it seems not working as well. Please let me know if u need more information.

    private final String apiPrefix = "/rest/api/3";
    @GetMapping(value = "/issues")
    @ContextJwt
    @ResponseBody
    public List<IssuesModel> getAllIssues() throws JsonProcessingException {
        String preEncodedUriString = apiPrefix + "/search?jql%3D";
        int total = 200;
        int startAt = 0;
        int maxResult= 100;
        List<IssuesModel> issues = new ArrayList<>();
        while (startAt<total){
            total=300;
            String jqlQuery = "project%3DTESTstartAt%3D"+ startAt +"%26maxResults%3D"+maxResult;
//            String jqlQuery = "project=TESTstartAt="+ startAt +"&maxResults="+maxResult;
            UriComponents uriComponents = UriComponentsBuilder.fromUriString(preEncodedUriString+jqlQuery).build(true);
            System.out.println(uriComponents);
            System.out.println(uriComponents.toUri());
            IssueJqlQueryCollection issueJqlQueryCollection = atlassianHostRestClients.authenticatedAsAddon().getForObject(uriComponents.toUri(), IssueJqlQueryCollection.class);
            assert issueJqlQueryCollection != null;
            System.out.println(startAt);
            issues.addAll(issueJqlQueryCollection.getIssues());
            startAt+=maxResult;
        }


        System.out.println(issues.size());
        return issues;
//        return atlassianHostRestClients.authenticatedAsAddon().getForObject(uriComponents.toUri(), String.class);
    }

pom.xml(part)

<atlassian-connect-spring-boot.version>3.0.3</atlassian-connect-spring-boot.version>
<dependency>
            <groupId>com.atlassian.connect</groupId>
            <artifactId>atlassian-connect-spring-boot-starter</artifactId>
            <version>${atlassian-connect-spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.connect</groupId>
            <artifactId>atlassian-connect-spring-boot-jpa-starter</artifactId>
            <version>${atlassian-connect-spring-boot.version}</version>
        </dependency>

2023-07-11 18:20:55.962 DEBUG 796 --- [nio-8080-exec-2] c.a.c.s.i.request.jwt.JwtGenerator       : Generating JWT with canonical request: [CanonicalHttpUriComponentsRequest@672ddcd2 method = 'GET', relativePath = '/rest/api/3/search', parameterMap = '[jql -> (project=TEST&startAt="0"&maxResults="100"),]']
2023-07-11 18:20:56.785 ERROR 796 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: "{"errorMessages":["Field 'startAt' does not exist or you do not have permission to view it.","Field 'maxResults' does not exist or you do not have permission to view it."],"warningMessages":[]}"] with root cause

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: "{"errorMessages":["Field 'startAt' does not exist or you do not have permission to view it.","Field 'maxResults' does not exist or you do not have permission to view it."],"warningMessages":[]}"

Hello @RogerFan

You have constructed the request incorrectly. You are putting startAt and maxResults into the JQL query when they must be declared as separate parameters, thus:

/rest/api/3/search?jql=project=test&startAt=0&maxResults=50

or:

/rest/api/3/search?startAt=0&maxResults=50&jql=project=test
1 Like

Hi @sunnyape

Thank you so much for the reply. I tried to use this one and it is working well. I can now send the correct request.

BTW, just letting the others know that u should change = to %3D only within project=test.

Best Regards,
Roger.