api.asUser().requestJira from resolver return 'Could not find product context' error after update forge version to 7.0

Hi, I’m experimenting with using the Forge resolver to retrieve issues from Jira in a custom UI project.

I’ve created a resolver that calls a function to fetch all issues retrieved from a JQL query

resolver.define('getIssues',async (request) => {
    let issues: IIssue []

    if (!request?.payload?.project){
        console.warn("No projects ")
        return []
    }
    console.info(request)
    const jql = `project in(${request?.payload?.project.key})`
    try{
        issues = await fetchAllIssues(jql)
        return JSON.stringify(issues) ;
    }catch (error){
        console.error('Error fetching issues: ', error)
        return []
    }   
});`

following function to get issues

export default async function fetchAllIssues(jql: string, startAt: number = 0, maxResults: number = 100): Promise<any[]> {
    const issues: any[] = [];
    let total = 0;
    do {
        const bodyData = JSON.stringify({
            expand: ["names", "schema", "operations", "transitions","changelog"],
            fields: ["summary", "status", "assignee","priority", "labels", "issuetype", "reporter","created", "updated"],
            fieldsByKeys: false,
            jql: jql,
            maxResults: maxResults,
            startAt: startAt
        });
        let data
        try{
            const response = await api.asUser().requestJira(route`/rest/api/3/search`, {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                body: bodyData
            });
            
            console.info(response.status)
            data = await response.json();
        }catch(error){
            console.error(error)
        }
        if (Array.isArray(data?.issues)) {
            issues.push(...data.issues);
            total = data.total;
        }
        startAt += maxResults;
    } while (startAt < total);
    return issues;
}

In the React app, I invoke my resolver

 useEffect(() => {
        invoke('getIssues', { project: context?.extension?.project }).then(setData);
      }, [context]);

Manifest permissions

permissions:
  content:
    styles:
      - 'unsafe-inline'
  scopes:
    - read:board-scope.admin:jira-software
    - read:jira-work
    - write:jira-work
    - read:issue-details:jira
    - read:issue-meta:jira
    - read:audit-log:jira
    - read:field-configuration:jira
    - read:issue-type-hierarchy:jira
    - read:user:jira
    - read:application-role:jira
    - read:avatar:jira
    - read:issue-type:jira
    - read:project:jira
    - read:project.property:jira
    - read:project-category:jira
    - read:project-role:jira
    - read:project.component:jira
    - read:group:jira
    - read:project-version:jira
    - read:user.property:jira
    - read:issue:jira
    - read:issue.vote:jira
    - read:comment:jira
    - read:issue.watcher:jira
    - read:status:jira
    - read:issue-security-level:jira
    - read:issue.changelog:jira
    - read:jql:jira
    - read:field:jira
    - validate:jql:jira
    - read:resolution:jira
    - read:license:jira
    - read:priority:jira
    - read:workflow:jira
    - read:issue-status:jira
    - read:field.default-value:jira
    - read:field.option:jira
    - read:sprint:jira-software
    - storage:app
    - write:dashboard.property:jira

This approach was working until a few days ago, but now when the app calls the function, Forge returns this message:

{ message: 'Could not find product context', name: 'Error' }

I have no idea why the app stopped working overnight. Could someone help me out?

1 Like

Hey, anyone from the Atlassian Forge team could shed some light here? Your inputs are highly appreciated! Tks! :slightly_smiling_face:

1 Like

Hey,

I have a UI Kit 1 (Jira AdminPage-) App that also shows this error when I run it via tunnel. In production it still seems to work. I could not find any additional details, since nothing more is logged.
An example trace ID is Trace ID: 5bd1e8d69a2844b9b2c58cb45baf665e.
It even seems to happen, when I comment out useProductContext(), which seems strange to me.

When I, as an experiment, switch the runtime to the new native runtime and tunnel, I get the following error:

Trace ID: 8e547891b7b34935a4830dc90b4a6087
There was an error invoking the function - Cannot read properties of undefined (reading 'token')

TypeError: Cannot read properties of undefined (reading 'token')
    at O (/private/var/folders/w8/0vhsb84d6dn2md0599gcz60m0000gn/T/tunnel-78228-ZjMQeYpruha2/index.cjs:1:147377)
    at <anonymous> (webpack://forge-ui-starter/node_modules/node-fetch/lib/index.mjs:1472:1)
    at new Promise (<anonymous>)
    at fetch (webpack://forge-ui-starter/node_modules/node-fetch/lib/index.mjs:1441:1)
    at <anonymous> (webpack://forge-ui-starter/node_modules/@forge/api/out/api/fetch.js:14:1)
    at Object.requestJira (webpack://forge-ui-starter/node_modules/@forge/api/out/api/index.js:13:1)
    at Object.callAPI (webpack://forge-ui-starter/src/index.tsx:50:1)
    at <anonymous> (webpack://forge-ui-starter/node_modules/@forge/ui/out/reconcile.js:31:1)
    at asyncMap (webpack://forge-ui-starter/node_modules/@forge/ui/out/reconcile.js:13:1)
    at <anonymous> (webpack://forge-ui-starter/node_modules/@forge/ui/out/reconcile.js:34:1)

Maybe someone at Atlassian can find out something with the trace IDs?

2 Likes

@CPS et al,

It certainly is helpful to have common issues like this worked in public so everyone affected gets the benefits. So, I appreciate that you’ve asked here first.

However, problems of this nature, where “it worked until X days ago,” usually indicate a bug caused by a recent Atlassian change. And, especially when getting into trace IDs, which are obviously only meaningful to Atlassians who can look into the logs. Because these require attention by an Atlassian, I think you would be best served by raising a developer support ticket.

1 Like

@ibuchanan Thanks for your attention. I’ll open a ticket!

1 Like

Hey everyone, I’ve submitted a ticket to Atlassian and the issue has been resolved.
@CPS , for testing, you’ll need to run a forge deploy once more.

Thanks for your attention! Cheer

2 Likes