Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Python Rest API question about code

Dixie September 29, 2019

Hello, im new bro in Python and try learnin this language and Attlasian Jira Service Desk.

Have this code:

from atlassian import ServiceDesk

sd = ServiceDesk(
url='https://sd.harmoni.pl',
username='bilyBoy',
password='gdsfHGasd')

my_requests = sd.get_issues_in_queue(6, 84, start=0, limit=50)
print(my_requests)


Take answer like this:

'self': 'https://sd.harmoni.pl/rest/servicedeskapi/servicedesk/6/queue/84/issue?start=0&limit=50'}, 'values': [{'id': '42759' , 'self': 'https://sd.harmoni.pl/rest/api/2/issue/42759', 'key': 'ITM-14698', 'fields': {'summary': 'test', 'issuetype': {'self': 'https://sd.harmoni.pl/rest/api/2/issuetype/10300', 'id': '10300', 'description': 'For general IT tasks and questions. Created by Jira Service Desk. ',' IconUrl ':' https://sd.harmoni.pl/secure/viewavatar?size=xsmall&avatarId=10800&avatarType=issuetype ',' name ':' IT Help ',' subtask ': False , 'avatarId': 10800}, 'components': [],' customfield_10119 ': {' id ':' 13 ',' name ':' Time to resolution ',' _links': {'self': 'https: //sd.harmoni.pl/rest/servicedeskapi/request/42759/sla/13 '},' completedCycles ': [],' ongoingCycle ': {' startTime ': {' iso8601 ':' 2019-09-27T20: 12: 40 + 0300 ',' jira ':' 2019-09-27T20: 12: 40.683 + 0300 ',' friendly ': '27 / 09/19 20:12', 'epochMillis': 1569604360683}, 'breachTime' : {'iso8601': '2019-09-28T13: 12: 40 + 0300', 'jira': '2019-09-28T13: 12: 40.683 + 0300', 'friendly': '28 / 09/19 13: 12 ',' epochMillis': 1569665560683}, 'breached': False, 'paused': False, 'withinCalendarHours': True,' goalDuration ': {' millis': 28800000, 'friendly': '8 hours'}, 'elapsedTime': {'millis': 646368, 'friendly': '10 min. '},' remainingTime ': {' millis ': 28153632,' friendly ':' 7 hours 49 min. '}}},' cre ated ':' 2019-09-27T20: 12: 40.000 + 0300 ',' reporter ': {' self ':' https://sd.harmoni.pl/rest/api/2/user?username=BiliBoy ', 'name': 'BiliBoy', 'key': 'biliboy', 'emailAddress':' biliBoy@har.pl ',' avatarUrls': {'48x48': 'https://sd.harmoni.pl/secure/ useravatar? ownerId = biliboy & avatarId = 10904 ',' 24x24 ':' https://sd.harmoni.pl/secure/useravatar?size=small&ownerId=biliBoy&avatarId=10904 ',' 16x16 ':' https: //sd.harmoni. pl / secure / useravatar? size = xsmall & ownerId = biliBoy & avatarId = 10904 ',' 32x32 ':' https://sd.harmoni.pl/secure/useravatar?size=medium&ownerId=biliboy&avatarId=10904 '},' displayName ':' Bili Boy ',' active ' : True, 'timeZone': 'Europe / Kiev'}, 'assignee': {'self': 'https://sd.harmoni.pl/rest/api/2/user?username=GROUP_1_line_IT', 'name' : 'GROUP_1_line_IT', 'key': 'group_1_line_it', 'emailAddress':' support_1_line_IT@harmoni.pl ',' avatarUrls': {'48x48': 'https://www.gravatar.com/avatar/7089a8a6bb768b864076ca61d6c031260303 = mm & s = 48 ',' 24x24 ':' https://www.gravatar.com/avatar/7089a8a6bb768b864076ca61ab6c0312?d=mm&s=24 ',' 16x16 ':' https://www.gravatar.com/avatar/7089a8a6bb768b864076caab ? d = mm & s = 16 ',' 32x32 ':' https://www.gravatar.com/avatar/7089a8a6bb768b864076ca61ab6c0312?d=mm&s=32 '},' displayName ':' Group - 1 IT line ',' active ' : True, 'timeZone': 'Europe / Kiev'}, 'updated': '2019-09-27T20: 12: 40.000 + 0300', 'status': {' self ':' https: //sd.harmoni. pl / rest / api / 2 / status / 10201 ',' description ':' Automatic Jira Service Desk was clearly generated when importing the business process ',' iconUrl ':' https://sd.harmoni.pl/images/icons/status_generic.gif ',' name ':' Waiting for support ',' id ':' 10201 ',' statusCategory ': {' self ':' https://sd.harmoni.pl/rest/api/2/statuscategory/2 ',' id ': 2,' key ':' new ',' colorName ':' blue-gray ',' name ':' Going to completion '}}}},

From this answer i need take (id or key) this issue, and i find this string: 

[{'id': '42759', 'self': 'https://sd.harmoni.pl/rest/api/2/issue/42759', 'key': 'ITM-14698',

Is this correct? Id this ticket = '42759'  and key  'ITM-14698' ?

When i use next code: 

print(sd.get_request_comments('14698'), 'SD answer')
or
print(sd.get_request_comments('ITM-14698'), 'SD answer')

 

{'errorMessage': 'The call was not found, or you do not have permission to see it.', 'i18nErrorMessage': {'i18nKey': 'sd.attachment.error.issue.not.found', 'parameters': []} }

I have permission for read and write, delete and other premission for work with comment's, where problem ? 

I make jira service desk with 8 project's and 3-5 queue in any project, when i ask information bout all open task's, i use ID correct project and ID correct queue 

sd.get_issues_in_queue(6, 84, start=0, limit=50)

but, when i ask comment's im just ask with ticket key, this key can be on other project or what? Why this is not work... ?


Finally i want try this code:

Example:
fields
= {'assignee': 'username'} sd.update_issue_field(issuekey,
My code:
# fields = {'assignee': 'biliBoy'}
# sd.update_issue_field('14698', fields)
- No errors and not working

My code: v2
# fields = {'assignee': 'biliBoy'}
# sd.update_issue_field('ITM-14698', fields)
- No errors and not working

but this code not work too ='( 


What i missing ? 

 

1 answer

0 votes
KRUNAL
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2020

Did you check all of your permissions from the JIRA developer dashboard because it seems like there is problem with configuration otherwise your code is I guess fine.

 

What this code internally does is calling the Python requests get() method that sends the AJAX request to JIRA Desk API and sending back to you a JSON response.

 

Now, JIRADesk provides you an API that will authenticate you, and based on your token, it will give you the JSON response.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events