Route is not populated properly

I am new for App Development. I tried building a product page. here i have to fetch boards list.
I am getting exception in fetch function.

Exception :

Error fetching boards: TypeError: Failed to fetch
    at fetch.js:17:49
    at Object.requestJira (index.js:21:12)
    at index.jsx:93:42
    at index.jsx:162:17
    at So (react-reconciler.production.min.js:151:471)
    at Ks (react-reconciler.production.min.js:195:111)
    at react-reconciler.production.min.js:191:391
    at _ (scheduler.production.min.js:13:203)
    at MessagePort.E (scheduler.production.min.js:14:128)

Code :

import React, { useEffect, useState } from 'react';
import ForgeReconciler , { render, ProjectPage, Fragment, Text, useAction, useProductContext, Heading, Label, RequiredAsterisk } from '@forge/react';
import { invoke } from '@forge/bridge';
import { Form, Select, Option } from "@forge/ui";
import { Macro, Table, Head, Cell, Row } from '@forge/ui';
import api , { storage, startsWith , authorize , route } from '@forge/api';
import SprintList from './components/sprintList';
....

   let url = (route`/rest/agile/1.0/board`);
    console.log('fetching asdasd:' , url);    
      const response = await api.asUser().requestJira(url);
      const data = await response.json();
.....

Obervation :

  1. route is not fetching the right base url / route.
    https://jira/rest/agile/1.0/board

kindly let me know what i am doing wrong.

You’re mixing and matching different packages. @forge/api should only be used for the backend.
Instead you should use requestJira from @forge/bridge in the frontend.

import { requestJira } from "@forge/bridge";

const response = await requestJira("/rest/agile/1.0/board");
const data = await response.json();

Thanks, I changed it. now i am having scope issue.

permissions:
  scopes:
    - manage:servicedesk-customer
    - read:jira-user
    - read:jira-work
    - write:jira-work
    - read:group:jira
    - write:group:jira
    - read:user:jira
    - read:avatar:jira
    - manage:jira-project
    - manage:jira-configuration
    - 'storage:app'

Error message :

  1. code: 401
  2. message: “Unauthorized; scope does not match”

How do i fetch which scope we are looking for and how to fix the same.

The scopes can always be found by reading the official API docs.

In your case, you need to add the following scopes to your manifest.yml:

permissions:
  scopes:
    - read:board-scope:jira-software
    - read:project:jira

Finally, re-deploy and upgrade your app for the new scopes to take effect.

Thanks . Found answers. one more question. any tutorial which i can read to add a component in backlog page . complete sprint dialog. etc. currently i see only issues, project page, admin only i can add ui component.

Hello @PrakashJeganathan

There are no Forge modules for Jira’s backlog page yet.

If you search this forum for ‘ui backlog’, you will find this recent thread where the question has been asked before.

1 Like

I am looking for api to fetch teams list associated with the user. i tried.
Account id fetched from /myself api.

    const orgResponse = await requestJira(`/rest/api/3/organization?accountId=${accountId}`);
    const orgData = await orgResponse.json();
    const orgId = orgData.values[0].id;

Unathorized Failure. i tried scope : - read:organization:jira but this scope is not available.

once i get the org id. i think i will use

 const response = await requestJira(`gateway/api/public/teams/v1/org/${orgId}/teams`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    });

    const data = await response.json();
    console.log('fetching team:', data.results);
    if (data === undefined || data?.results === undefined) {
      return [];
    }

    return data.results;

Any better api for fetching the teams.

    console.log('Organization ID:', orgId);

Hello @PrakashJeganathan

Please do not keep re-opening the same thread with new questions on different topics or posting the same question across multiple threads.

Your original question for this thread has been answered. Please mark the original answer that was provided by @rcsr for your original question as correct, then start a new thread for new questions.