Make a request to REST API in Forge App - sprints

Hello,

I’m building a Forge Application. In the past, I was able to make some requests to REST API v3. For instance, I was able to append a scope read:jira-user to my manifest.yml and make a request like this one:

resolver.define('getUsers', async ({ context }) => {
  const {
    extension: {
      project: { key: projectKey },
    }
  } = context;

  const response = await api.asApp().requestJira(
    route`/rest/api/3/user/assignable/multiProjectSearch?projectKeys=${projectKey}`,
    {
      headers: {
        'Accept': 'application/json'
      },
    },
  );
  ...
});

My understanding is that the code above uses REST API 3.

Question 1 - can my Forge app access REST API 1?

Let’s say that I want to get the sprint data. I thought that all I have to do is to append new scope to permissions section: read:sprint:jira-software (see the documentation https://developer.atlassian.com/cloud/jira/software/rest/api-group-sprint/#api-rest-agile-1-0-sprint-sprintid-get) and then make a request:

resolver.define('getOtherData', async ({ payload }) => {
  const sprintResponse = await api.asApp().requestJira(
    route`/rest/agile/1.0/sprint?state=active`,
    {
      headers: {
        'Accept': 'application/json'
      },
    },
  );

  const sprint = await sprintResponse.json();
  console.log(sprint);
});

Unfortunately I what I got in my console is:
{ code: 401, message: 'Unauthorized; scope does not match' }.

Question 2 - what am I missing here?
Question 3 - should I customize the second request to support OAuth 2.0 manually? My guess is that I need append a user token to my request. How to do that?

Thank you in advance.

Have you deployed the app and upgraded your installation? i.e. forge deploy && forge install --upgrade

Hello @Luca

The path /rest/agile/1.0/sprint?state=active is invalid.

If you refer to the documentation, you’ll see the path for the Get Sprint endpoint is /rest/agile/1.0/sprint/{sprintId} and that endpoint doesn’t support any such parameter called state.

@rcsr Yes, I did it.
@sunnyape You were right, I followed this thread and I have made a mistake.

Now, everything works fine. It’s good to know that I can call v1 the endpoints without additional tokens.

Thank you!

1 Like