Can't make calls with 3LO

Hi,
Im trying to use the JIRA API.

According to the documentation, I must retrieve the authentication code once the user has logged, then exchange it for the access token. Finally, I must get the cloudId of my site.
So far, doing all of this I got a get call that retrieves:

[{“id”:“ID_OF_MY_SITE”,“url”:“https://MYSITE.atlassian.net”,“name”:“MYSITE”,“scopes”:[“read:application-role:jira”,“write:attachment:jira”,“write:comment:jira”,“read:project-category:jira”,“read:project:jira”,“write:issue:jira”,“write:comment.property:jira”,“read:issue-type-hierarchy:jira”,“read:user:jira”,“read:avatar:jira”,“read:issue-type:jira”,“read:issue:jira”,“read:project.property:jira”,“read:project.component:jira”,“read:group:jira”,“read:project-version:jira”],“avatarUrl”:“IMAGE”}]

So seems like everything is okay, however when I try to build a URL to make a get call it always return a 404. Documentation says that urls should look like this: https://api.atlassian.com/ex/jira/11223344-a1b2-3b33-c444-def123456789/rest/api/2/project and I already tried with some similar to that one and don’t work (Obviously with my cloudid and the access token).

Can someone tell me how can I make APIs calls for both Confluence and Jira using 3LO?

Welcome to the Atlassian developer community @AllnTrejosSalazar,

I was able to successfully use my access token to call the project resource so it’s not systematically broken. I also tried a few variations that may help us diagnose your problem.

When I change my Bearer token to foo (an invalid token), then I still get a 200 but with an empty JSON array.

When I change my cloudid to foo (an invalid Cloud ID), then I get 404 with an error body:

{
	"timestamp": "2023-09-27T17:22:55.767972Z",
	"status": 404,
	"error": "Not Found",
	"message": "No message available",
	"path": "/ex/jira/foo/rest/api/2/project"
}

I’m not sure what’s going wrong between the accessible-resources and your URL construction, but it seems like there’s a wrong cloudid in there somehow. Maybe you can confirm by seeing if my URL gives you a different response:
https://api.atlassian.com/ex/jira/c68adbe0-2b09-4add-b08e-eb5797b31bc9/rest/api/2/project

There is another way to check your cloudid. Use GET on the /_edge/tenant_info path. For example, you can see my cloudid using (cloudids are no more secret than the URLs):
https://devpartisan.atlassian.net/_edge/tenant_info

So far, it looks like you are on the right path. As long as your OAuth app has both Jira and Confluence scopes, it can get authorization to the site and access endpoints for both.

Let us know what you learn.

Hello, thanks for your answer.

Well, I made some changes and the call to rest/api/2/project gets:
[{“expand”:“description,lead,issueTypes,url,projectKeys,permissions,insight”,“self”:“https://api.atlassian.com/ex/jira/cloudID/rest/api/2/project/10000",“id”:“10000”,“key”:“TEST”,“name”:“Test”,“avatarUrls”:{“48x48”:“LINK”,“24x24”:“LINKl”,“16x16”:“https://api.atlassian.com/ex/jira/c4362a8a-a5da-46ac-af15-7090b15c27c5/rest/api/2/universal_avatar/view/type/project/avatar/10417?size=xsmall”,“32x32”:“LINK”},“projectTypeKey”:“software”,“simplified”:true,“style”:“next-gen”,“isPrivate”:false,“properties”:{},“entityId”:“ID”,“uuid”:"ID”}]
So, seems like it is working, however I’d like to maybe get all the issues in a project called TEST and doing this calls:

mainUrl = https://api.atlassian.com/ex/jira/

mainUrl/MY-CLOUD-ID/rest/api/2/search?jql=project=TEST

or

mainUrl/MY-CLOUD-ID/rest/api/2/issue/TEST-1
(To get an specific issue in jira)

or

mainUrl/MY-CLOUD-ID/rest/api/2/events

I get 403:Forbidden, so this is so weird. Acording to the documentation, 403 is returned if the user does not have permission to complete this request however scopes and access token are okay :thinking:

By the way, I’m currently using java and this is my code so far:

private void getIssues(){
//I have change apiUrl to the options I mentioned above
        String apiUrl = "mainUrl/MY-CLOUD-ID/rest/api/2/events";

        try {

            URL url = new URL(apiUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            conn.setRequestProperty("Authorization", "Bearer " + accessToken);
            conn.setRequestProperty("Accept","application/json");
            conn.setRequestProperty("Content-Type","application/json");

            int responseCode = conn.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK){

                BufferedReader reader = new BufferedReader(new 
                InputStreamReader(conn.getInputStream()));
                StringBuilder response = new StringBuilder();
                String line;

                while ((line = reader.readLine()) != null){
                    response.append(line);
                }
                reader.close();

                System.out.println(response.toString());
            } else {
                System.out.println("ErrorCode: " + responseCode);
                System.out.println("ErrorMessage: " + conn.getResponseMessage());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Running this code I get:
ErrorCode: 403
ErrorMessage: Forbidden