Get JIRA baseurl by giving credentials through rest api

Mohammed Shaik Mehboob January 30, 2018

Hi guys, I have been trying to get the base url of jira through rest api by passing credentials, but unable to do it. please help...

Thank you

3 answers

1 vote
ankush December 22, 2021

Little late to the party, but as this is not answered still after 2 years, I'll try to help.

Once you have oauth access token of the user, you can make a get call on 

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

This will give a list of all the sites accessible to the user along with it's cloudIds and siteUrls.

More info here: https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/

1 vote
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 30, 2018

Try to make a REST call to the endpoint called /rest/api/2/serverInfo

It will contain the baseUrl as a parameter of that Jira instance.

Mohammed Shaik Mehboob February 1, 2018

to make rest call i need to give basurl

Mohammed Shaik Mehboob February 1, 2018

How to make a rest api call without giving domain ?? i need domain to make a call and that is what i want to get 

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2018

@Mohammed Shaik Mehboob 

As already mentioned in the other replies, in order to call a REST API endpoint you must already know the base url.

Also, id.atlassian.com is mainly used for Single Sign On. This means that if you have multiple JIRA instances, after you log into id.atlassian.com, you can access all your JIRA instances without having to log-into all of them one by one.

Still,  after being authenticated into id.atlassian.com, you need to know which one your JIRA instances are in order to access them. :) 

I hope this helps clarifying.

 

Best Regards,
Dario
Atlassian Cloud Support  

Mohammed Shaik Mehboob February 27, 2018

@Dario B i really appreciate it, i was trying to do something different but that didnt end up well i couldnt explained it properly to you guys.

Thanks again

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2018

You are very welcome @Mohammed Shaik Mehboob. Please do not hesitate asking further questions or opening different threads if needed.

 

Have a nice day!

Dario

RodPienaar January 4, 2020

I know this is an old thread but I stumbled on it looking for the same answer as Mohammed and this thread is not answered.  Maybe phrased in a different way it can lead to an answer.

I am building a plugin that will hopefully have many users.  When making calls to the rest API should I always be using my-domain (hard coded into my plugin) or should I be using a domain that is relevant/applicable to my user/s?

If its the latter then there needs to be a way to lookup the domain of my user and dynamically use it as the base-url to make API calls.

***Edited***

I did a bit more searching and found this:

3.2 Construct the request URL

Requests that use OAuth 2.0 (3LO) are made via api.atlassian.com (not https://your-domain.atlassian.net). Construct your request URL using the following structure:

Since I am using OAuth 2 this means I need to change my request URL anyway. 

https://developer.atlassian.com/cloud/confluence/oauth-2-authorization-code-grants-3lo-for-apps/

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2020

Hi @RodPienaar ,

Welcome to the Atlassian Community.

 I believe you have already found the answer by yourself, however, please confirm this is the case.

Also, for the future, please notice that this is not the best place to get help on development  related questions. The right resources are listed in https://developer.atlassian.com/resources. 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2018

Er, if you know where to go to ask a Jira for its base url, then you already have it.

Mohammed Shaik Mehboob February 1, 2018

I am implementing JIRA in my application and i want to verify credentials through rest api without asking for baseurl from user

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2018

I'm afraid your requirement is nonsense.

If you don't know the base url, then you can't go to it to ask it where it is.

Imagine a real-world example.  You know you want to get a telephone number for someone.  What you're asking is to be able to ring them up to get it.  But you don't have their number so you can't.

You need to re-think what you are doing here.  You MUST give it a base url somehow, if you want to connect to it.

Mohammed Shaik Mehboob February 1, 2018

Thanks for your concern. 

I believe you are good in imagination, imagine how you are logging into jira by giving just credentials, you dont see your domain/baseurl while logging. I want to implement the same.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2018

Yes you do, it's in the browser's address bar.

Mohammed Shaik Mehboob February 1, 2018

That come after you log in 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2018

No.  It does not.

To get to a login screen, I have to enter a baseurl into my browser.  Jira sees I am not logged in and asks, then it's username and password.

How do you get to a login screen if you don't enter the baseurl to get to it?

Mohammed Shaik Mehboob February 1, 2018

https://id.atlassian.com/login

I'm afraid you are using some alternate url.

Go to the url please, You need to enter only username.email and password you will be logged into your account no need of baseurl.

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 1, 2018

Server and Cloud platforms work differently in this regard.  All the Jira Cloud instances are forcing users to go through he ID site as means to authentication, but Jira Server has no such requirement.  For Jira Server, the Jira site itself is handling authentication, unless you are using some other SSO solution like Crowd, Okta, etc.

Could you provide us more information about what you are trying to accomplish here?  Are you trying to create a plugin for Jira Cloud or for Jira Server?  

The rest endpoint I cited was actually for Jira Server.   If you were using Jira server it is possible that you could be connecting to that Jira instance on some other address that is not the baseurl (such as an IP, a simple hostname, or localhost if access directly).   In cases like that, then you can still make a rest call to that address in order to find out what the base url value has been set to in that instance.  

Hence when you mentioned base URL, I think both Nic and myself believed you were referring to Jira Server.  Since in Jira Cloud, you cannot set the base URL, it is hard coded based on the domain name you selected when first setting up that site.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2018

Ok, just to clarify where I am coming from.  Yes, you go to id.atlassian.com/login and that logs you in to your Atlassian account.

Now, I have access to a number of Atlassian and Cloud systems.   Once logged in to my Atlassian account, I've got a token that will let me in to them.

Now, tell me how I get to Jira 1, Jira 2 or Jira 3?

Suggest an answer

Log in or Sign up to answer