BaseUrl of api Jira Service Management app

I’m building a new Jira Service Management app that relies on the knowledge base API to retrieve articles. While the API requires a base URL to be specified, . Ideally, the app should automatically discover the base URL of the Jira Service Desk instance where it’s installed to get the arcticles that belong to its proper user,but for the api to work i specified mine , i’m using connect, how can i ensure that?

@MohamedNajah,

I’m not sure I understand where you’re having a problem. The Connect lifecycle hook contains both baseUrl which would be used in making API requests, and the displayUrl which would be for creating UI hyperlinks. Then, you would GET /rest/servicedeskapi/knowledgebase/article
to get articles from the Knowledgebase. Are you using one of the Atlassian Connect frameworks (Express or Spring Boot) to build your app?

1 Like

I mean that to use the api and extract the knowledge base articles i used my baseurl and my api token,but for each user of the app ,its important to fetch the articles using his baseurl and api token,and my app cannot do that,so i’m looking for a way to get the baseurl of each user nd stock the baseurl as a variable to use it to fetch and get his articles

@MohamedNajah,

You tagged this topic with Atlassian Connect. What you’re asking would not be possible with API Tokens.

Yes i’m using connect (ace),so what are the alternatives please ?
Because It seems like a simple operation ,to fetch the endpoint from the user baseurl and not from my baseurl,this way it will give him his knowledge base articles and not mine
So for example :
lets suppose this is the api:
www.mohamednajah.atlassian.net/api/rest/knowledge-base/articles

The base url : mohamednajah, must change for every user to be his baseurl ,in order to get his knowledge base articles.
I’m not sure but i guess its called context parameters.

@MohamedNajah,

I don’t know much about why you picked Atlassian Connect, but if you are already comfortable in JavaScript, then I would recommend looking at Atlassian Forge. Forge is not required to do what you want; I just think the docs & examples are better written for this 1 thing, and that you’ll have more Atlassians here able to respond and provide help about Forge.

It seems like the capability you want is described in the Atlassian Connect Express docs as “How to send a signed outbound HTTP request back to the host”. The AC Express framework provides a factory for Atlassian-specific HTTP clients (addon.httpClient) that automatically “injects” the correct Base URL so you don’t have to manage that in your code. Inserting the KB endpoint, here’s how that might look (notice, no dash in knowledge-base):

var httpClient = addon.httpClient(req);
httpClient.get('/rest/servicedeskapi/knowledgebase/article', function(err, res, body) {
  ...
});

to be honest i’ve used forge but i found many issues during deployment ( also problem with tunneling) so iswitched to connect.
thank you for your indication for the factory but when i try it i receive an error of

“{ ctx: {} } Authentication verification error (401): Could not find authentication data on request
GET /get-articles 401 4.396 ms - 59”

this is my code

would you suggest any solution for the problem above?

@MohamedNajah,

This is a different problem now. The auth mentioned is now about how to provide auth on your route, which is explained in “ How to secure a route with JWT”.

yes i checked the documentation , and i wrote my code based on it, could you take a look at it ,i’m new here (but i’m sure i checked the documentation well )

@MohamedNajah,

I’m more of a generalist on this forum. I’m afraid I’m not familiar with building for Atlassian Connect Express, nor on debugging. I don’t have more help to offer.

Hey, I’ve decided to completely revamp my project and start fresh using Forge, as per your suggestion. However, I’ve encountered an issue with the Forge API. I’m reaching out for assistance in troubleshooting this problem. Below is my new post detailing the issue. Can you provide support with this please?