Product fetch API ignores query string

It looks like the requestJira and requestConfluence APIs from the @forge/api module are ignoring the query string if one is passed in the route. For example, when I try to use a custom UI resolver that retrieves all issue comments except the first one (using the startAt search param), I still get all comments:

resolver.define("example", async () => {
  const response = await api
    .asUser()
    .requestJira(
      route`/rest/api/3/issue/{issueKey}/comment?startAt=1`
    );

  return response.json();
});

Response:

{
  "startAt": 0, <- This should be 1, not 0.
  "maxResults": 1048576,
  "total": 3,
  "comments": [
    { ... }, <- This comment should not be returned.
    { ... },
    { ... }
  ]
}

When I make the same request outside of a Forge function (using a REST client or requestJira from @forge/bridge), I get the correct result:

{
  "startAt": 1,
  "maxResults": 1048576,
  "total": 3,
  "comments": [
    { ... },
    { ... }
  ]
}

Do you know if there’s a workaround for this problem?

Hi @klaussner,

Unfortunately I couldn’t reproduce the issue.

I’ve created the app below:

import ForgeUI, {
  render,
  Fragment,
  Text,
  IssuePanel,
  useProductContext,
  useState,
} from "@forge/ui";
import api, { route } from "@forge/api";

const fetchCommentsForIssue = async (issueKey) => {
  const res = await api
    .asUser()
    .requestJira(route`/rest/api/3/issue/${issueKey}/comment?startAt=1`);

  const data = await res.json();
  console.log(`Returned data:`, JSON.stringify(data, null, 2));
  return data.comments;
};

const App = () => {
  const context = useProductContext();
  const [comments] = useState(
    async () => await fetchCommentsForIssue(context.platformContext.issueKey)
  );

  return (
    <Fragment>
      <Text>
        There are {comments.length} comments (not including the first one)
      </Text>
    </Fragment>
  );
};

export const run = render(
  <IssuePanel>
    <App />
  </IssuePanel>
);

I have used @forge/api version 2.4.0.

Can you think of what you did differently to what I did?
Thanks!

2 Likes

Thanks for your help, @DganitZuriel! I tried out your example and had the same problem, but only when using the Forge tunnel. It turned out that I used an old version of the tunnel and after updating to the latest version, everything works as expected.

2 Likes

Hi @klaussner,

It’s great to hear!
I’m glad that the issue was solved :slight_smile:

Cheers!