ERR_CONNECTION_REFUSED Route parameter for requestJira() not working as expected

Running into an issue with the route parameter in requestJira() method.

import api, { route } from "@forge/api";
const App = () => {
// State for app removed for brevity
useEffect(() => {
    invoke('getText', { example: 'my-invoke-variable' }).then(setData);
    invoke('getCtxt').then(setSiteURL).then(()=>{getProjectList(siteURL)})
   
     console.log({siteURL})
  }, []);

const getProjectList = async (url) => {
    console.log('##################');
    const response = await api.asApp().requestJira(route`/rest/api/3/project/search`, {    
      method: 'GET'  
    });
    const project = await response.json(); 
    result = project.values;
   
    return result;
  }
}

checking the console it doesnt appear the route is fetching the base URL as expected and am getting a connection refused due to this
GET https://jira/rest/api/3/project/search net::ERR_CONNECTION_REFUSED

I have tried api.asApp() and asUser(), both have the same outcome.

I have also tried fetching the baseURL from a resolver context, which allows me to display the baseURL in text when loaded, however trying to use the baseURL returned from the resolver in place of the route parameter, I receive an error stating explicitly to use the route.

resolver.define('getCtxt', (req) => {
  console.log(req.context.siteUrl);
  let siteUrl = req.context.siteUrl;
  return siteUrl;
});
...
 const getProjectList = async (url) => {
    console.log('##################');
    console.log(url)
    const response = await api.asApp().requestJira(`${url}/rest/api/3/project/search`, {    
      method: 'GET'  
    });
    const project = await response.json(); 
    result = project.values;
   
    return result;
  }


Uncaught (in promise) Error: You must create your route using the ‘route’ export from ‘@forge/api’.
See https://go.atlassian.com/forge-fetch-route for more information.

The documentation linked here takes me to Authorize API, but there aren’t any method signatures relevant to what I’m trying to accomplish. I’m just trying to grab a list of projects on the installed Jira instance.

my scopes for reference:

permissions:
  scopes:
    - manage:jira-project
    - read:avatar:jira
    - read:custom-field-contextual-configuration:jira
    - read:group:jira
    - read:issue-type:jira
    - read:jira-user
    - read:jira-work
    - read:jql:jira
    - read:project:jira
    - read:project-category:jira
    - read:project.component:jira
    - read:project.property:jira
    - read:project-role:jira
    - read:project-type:jira
    - read:user:jira
  content:
    styles:
      - unsafe-inline

Thanks in advance for any insight. Cheers

I think we’re supposed to not use route in forge frontend code. As per https://developer.atlassian.com/platform/forge/apis-reference/ui-api-bridge/requestJira/ we simply need to call

import {requestJira} from "@forge/bridge"

const response = await requestJira(`/rest/api/3/project/search`, {method: 'GET'})

Have you tried this approach already?

Cheers

2 Likes

Unfortunately I have, running it without prompts me in console to use route exports.

Can you share the content from the console? It should show the site. In your example, it shows https://jira/rest/… Is “jira” just a placeholder in your post for your site? It should be something like ".atlassian.net

I am relatively new to Forge but I believe the domain or base URL comes from the instance on which you install your app.

In that case, use requestJira from `“@forge/bridge” (that’s for front-end → Jira calls) package instead of “@forge/api” (that’s for back-end → Jira calls) ref

edit:
Unless you’re using UI Kit 1… :thinking: What front-end actually are you using in your Forge app? Is it UI Kit, UI Kit 2 or Custom UI?

Do you use the UI Kit and @forge/api or do you use the custom UI with bridge? I have been using the UI kit and @forge/api. The getProjectList function looks ok. I would call it this way:

const [projectList] = useState(async () => await getProjectList());

This is part of the issue I’m facing, not sure why but given the rest of the commentary on this thread (thanks all!) I’m assuming it has something to do with whatever frontend I’m using.

For some reason using route within the request is failing to interpret the domain correctly, and the console statement is showing route interpolating it as https://jira/rest… vs my actual dev-test.attlassian.com site

Thanks for the response, I’ll give removing the forge/api imports. I have forge/bridge imports in my app (including requestJira), but I may have gotten my wires crossed.

As for “what front-end am I actually using”; I was following along with documentation for UI kit 2 for some of the other form elements will eventually be using, but at this point its relatively unclear how to tell explicitly what I’m using… likely some weird amalgamation of the two at this point :upside_down_face:.

I am attempting to not use custom ui since this is a small internal tool and I had a bad time using custom UI with connect apps at previous companies lol.

1 Like

Removing the Api usage and using requestJira from the forge/Bridge import without using Route was the answer! Thank you for your assistance and for providing clarity on which side of the framework to use api and bridge packages in :slight_smile:

2 Likes