How to get domain adress for REST API request

A very newbie question but I can’t find the answer anywhere.
The endpoint of the REST API is straight forward

your-domain.atlassian.net/XXX where XXX is the endpoint. that’s the obvious part. The question is → how to obtain "your domain
As I understand the request is done in the context of the company instance where the plugin is installed. How to get it?

Depends on what kind of app/plugin you’re building.

As an example, if you’re building an app with Atlassian Connect you’d get the baseurl with the installation payload from the install lifecycle event.

https://developer.atlassian.com/cloud/jira/platform/connect-app-descriptor/#lifecycle-http-request-payload

It’s a rest api (angular + spring boot) application. I understand that bseUrl is related to my app but I want to make a rest api call based on the instance on which the app is isntalled so i don’t think this is the solution.
I want to get the “your-domain” from the instance on which the app is installed. this is how i understand it

here is my second issue with that which describes how the app looks like: How to store company context in external storage

@fixianovic,

If you are using API tokens, there is no meaningful sense of “installed”. Your client will need to know the site name (the part you are calling “your-domain”) a priori.

However, if you are using OAuth 2.0, then your original post makes an incorrect assumption (a common misunderstanding). Request URLs for OAuth 2.0 look like:

https://api.atlassian.com/ex/jira/{cloudid}/{api}

Your client obtains that cloudid by using the access token with this endpoint:

https://api.atlassian.com/oauth/token/accessible-resources

That way, the client is “installed” by means of a user doing an OAuth authorization code grant flow and then asks accessible-resources which sites it can access.

1 Like

@ibuchanan thank you very much for your answer but I must admit that I don’t follow a few things. Maybe you can help me with that.

I installed my own app on my instance via manage applications. I added url to atlassian-connect.json which is hosted by my app. As I understood the official tutorial this is a common way to install an app. Now my app can be run on multiple instances of Jira via many companies. If I have a one db and I store all the data I need to have a method to connect those data with a specific instance/company.

As I also understand I’m making a REST API call using the domain of the instance on which the app is installed. So if this is company1.atlassian.net I use “company1” instead of “your-domain”. If it’s company2.atlassian.net i use “company2”. is that correct? If yes, how can I obtain this part?

I feel I’m missing something obvious :slight_smile:

@fixianovic,

I see. I think I am the one confused. When you said, “It’s a rest api…” I assumed you meant it’s not using Atlassian Connect. From what you just described, that’s what you have (atlassian-connect.json was the clue for me). Hence, @rwhitbeck provided the answer:

you’d get the baseurl with the installation payload from the install lifecycle event.

@ibuchanan I’m new in this world so I might be mixing some topics. I’ll try to devide it into basic elements to be as clear as possible.

  1. I’m creating a cloud app
  2. my stack is: angular for frontend and spring boot with mysql for backend
  3. front and back parts are connected with each other over rest API
  4. my app is providing a new object: let’s call it a RISK for simplicity
  5. all Risks are kept in my database
  6. on my front part I’m providing a form for creating new Risk and generating a list of them
  7. the installation proces was based on that: https://developer.atlassian.com/cloud/jira/platform/getting-started-with-connect/
  8. what I want to do is to install my app on multipla instances (in many companies) and store their data in one DB
  9. to do that I need to seperate data one from another company so the SQL query look like this “select * from risks where company_id = xxx”
  10. I also want to perform some request to jira REST API so I need to have the domain name

“baseURL” - as I understand this is base url of my app. not of the instance on which it’s installed as this file is provided by my app. So I don’t understand how could I use that to perform a jira rest api request.

Sorry for the trouble. I just want to fully understand this and I can’t find the answers in the documentation :frowning:

So my two basic questions are:

  1. do i correctly I understand that jira api request is done with the domain name of the specific instance?
  2. how can I get some kind of company id?

@fixianovic,

“baseURL” - as I understand this is base url of my app. not of the instance on which it’s installed as this file is provided by my app. So I don’t understand how could I use that to perform a jira rest api request.

baseUrl is “overloaded”. In the Connect descriptor, yes, it is the base URL of your app. In the lifecycle payload, it means:

URL prefix for this Atlassian product instance. All of its REST endpoints begin with this baseUrl. Do not use the baseUrl as an identifier for the Atlassian product as this value may not be unique.

For your summary questions:

  1. do i correctly I understand that jira api request is done with the domain name of the specific instance?

Yes. That’s provided in the lifecycle payload as baseUrl.

  1. how can I get some kind of company id?

You can’t. At least, you can’t get anything that identifies a company. You can get both a URL for the site, and the clientKey does uniquely identify an instance of Jira, even if the site name changes. For most cases, that is close enough.

1 Like

@ibuchanan sounds like things that I’m looking for. Thank you very much :slight_smile: Now I just need to learn how to get values from the atlassian-connect and clientKey but this should be much easier