Got 301 when log in Jira by rest API

Hi all,

I'm trying to write a plugin to do some simple queryies in jira. What shall I do first is to log in jira, right? I do it in the following way:

#!/usr/bin/env python

import urllib
import httplib
import json

test_data = {"username":"username","password":"password"}
test_data_urlencode = json.JSONEncoder().encode(test_data)


requrl = 'https://company.com/rest/auth/1/session'
headerdata = {"Content-Type":"application/json"}

conn = httplib.HTTPConnection("company.com")

conn.request(method="POST",url=requrl,body=test_data_urlencode,headers = headerdata)

response = conn.getresponse()

res= response.read()
print res

But I got output like this:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://company.com//rest/auth/1/session">here</a>.</p>
</body></html>

Could you help me fix this? Thank you.

1 answer

Well personally I suggest you to use python requests if you insist using method above. Or you can use jira python client.

You don't have to 'login first', just send request to endpoint you want with header "Authorization: Basic BASE_64", you can find more info at https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,117 views 13 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot