2

I'm trying to write API client for Jira with Python requests lib according reference: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

Request to be generated:

http://localhost:8080/rest/api/2/search?jql=assignee=charlie&startAt=2&maxResults=2

As I know, parameters to GET request should be passed as dictionary like:

 params = {'assignee':'charlie', 'startAt':'2'}

But all main parameters are nested in jql parameter, so I assume there is should be a nested dict like:

 params = {'jql': {'assignee': 'charlie'}}

But that's doesn't work - as a result I've got request to

/rest/api/2/search?jql=assignee

As expect /rest/api/2/search?jql=assignee=charlie using

r = requests.get(url, params=params)

How to manage such request?

UPD:

To be more clear, I'd like to wrap request in a method with kwargs, like:

search_query(assignee='charlie', startAt=1, etc...)

And then generate a query using this params, but maybe there are any other ideas.

1 Answer 1

0

You are missing couple of key parameters, mainly if you are pushing data via requests, the data go into the data argument. Also the moment you push JSON data, you need to set the headers correctly as well. The last thing is authentication. Have you tried to post it in this manner?

import json
requests.post(url=url, headers={"Content-Type": "application/json"},
              auth=('username', 'password'), # your username and password
              data=json.dumps(params)
              )

Also by the JIRA documentation you've provided (https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/) if you want to push query as data, the url you want is /rest/api/2/search.

Sign up to request clarification or add additional context in comments.

1 Comment

The question is about Get request - it doesn't use data to push, just a parameters in a url string like ?param1=value1&param2=value2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.