How to use forge api.asUser().requestJira() with self URL

I have a self URL like https://your-domain.atlassian.net/rest/api/3/project/MKY/role/10002 from a previous api call like get project roles for a project.

Now I would like to retrieve further information calling these self URLs pointing to get project role information in the REST API.

But if I call api.asUser().requestJira(self) then Forge is throwing and error, that I need to use route.

I read here about Product authentication and route I should use assumeTrustedRoute, but I don’t know what that means and how to do that.

Can anyone provide some sample code how to use assumeTrustedRoute? Anybody know how to call a self URL?

Best regards
Holger

Hi @Holger,

In this case I would probably remove the site URL from the path and add the remaining part of the URL to the requestJira method using route as well.

What do you think?

The assumeTrustedRoute difference is related to how the request parameter are treated, it is still expecting just API endpoint without the site URL.
Just to leave an example here, here is how to use it:

import api, { assumeTrustedRoute } from "@forge/api";
...
const res = await api
    .asUser()
    .requestJira(assumeTrustedRoute("/rest/api/3/project/10000/role/10003"));

Cheers,
Caterina

1 Like

Hello @ccurti, thank you for your support! If also assumeTrustedRoute expects an URL without site, then I cannot use the self URL directly, need to create substring and then I can also use regular requestJira() with route. So, this is my code now.

const fetchSelf = async (self) => {
    let position = self.search("/rest/api/");
    let subself = self.substr(position);
    const res = await api
      .asUser()
      .requestJira(route`${subself}`);
  
    const data = await res.json();
    return data;
};

Strange concept that requestJira() does not accept a self URL. Maybe something to think about at Atlassian.

Best regargs
Holger