Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I can’t create ticket or call ticket using Jira service desk api

I'm trying to use the jira service desk api but I couldn't call or create service desk tickets and tried everything. I am using python.

1 answer

4 votes
Hana Kučerová Community Leader Nov 23, 2021

Hi @Francisco Alberto Franjul Rodríguez ,

welcome to the Atlassian Community!

Would you please share more information? How does your code looks like? Do you get any error message? Which one? etc.

Thank you.

 

Hello @Hana Kučerová 
Thanks for reaching out!


I am making an integration that can read and write tickets made with servicedesk.

I tryed using the documentation about integrating with servicedesk but It all seems to be deprecated.

Since there seems to be no updated documentation I don't know which method to call in order to read created servicedesk tickets or create new ones.

 

 

 

This is the code.

from urllib.error import HTTPError

import json

from atlassian import ServiceDesk

 

_serviceDesk = ServiceDesk(

    url='https://penadefillo.atlassian.net/',

    username=*****@*****.com',

    password='*****')

 

# get service desk with ID

# data = _serviceDesk.get_service_desk_by_id(5)

#print(data)

 

#GET client request

# data = _serviceDesk.get_my_customer_requests()

#print(data)

# Metodo para obtener los usuarios en la organizacion pero no se usa en la empresa

#data = _serviceDesk.get_users_in_organization(1,limit=100)

#print(data)

 

#Comment attachement 

#print(data)

# def post():

#     data = _serviceDesk.create_attachment(

#      service_desk_id=5,

#      filename='/Users/franciscoalbertofranjul/Downloads/IMG_5650.JPG',

#      issue_id_or_key='RRHH-448',

#      public=True,

#      comment='Probando Service Desk desde Python'

#     )

#     return data

#

#     data = _serviceDesk.create_request_type(

#         service_desk_id=5,

#         request_description='Este request esta siendo probado desde python',

#         request_name='Probando el serivcio desde Python',

#         request_type_id='',

#         request_help_text='',

#     )

#     return data

# print(post())

 

 

#create comment

#data = _serviceDesk.create_request_comment('RRHH-217',body="Estoy probando la API de Python", public=True)

#data = _serviceDesk.create_customer_request(5, 'RRHH-330', None, None)

#data = _serviceDesk._create_oauth2_session('https://auth.atlassian.com/authorize?audience=api.atlassian.com&client_id=iKWgVmjcufHV2YmuoU9HqyfM5NI4eJhT&scope=read%3Aservicedesk-request%20manage%3Aservicedesk-customer&redirect_uri=https%3A%2F%2Fpenadefillo.atlassian.net%2Fjira%2Fservicedesk&state=${YOUR_USER_BOUND_VALUE}&response_type=code&prompt=consent')

 

#data = _serviceDesk.get_service_desk_by_id(5)

#print(data)

# data = _serviceDesk.create_request_type(

#     request_type_id=17,

#     service_desk_id=5,

#     request_description='Probando el Jira Service Desk Python Api',

#     request_name='Solicitud de Vacaciones',

#     request_help_text='Probando el Jira Service Desk Python Api')

#

# print(data)

# def create_request_type(

#         self,

#         service_desk_id,

#         request_type_id,

#         request_name,

#         request_description,

#         request_help_text,

# ):

#     data = {

#         "Vacaciones": request_type_id,

#         "Vacaciones Prueba": request_name,

#         "Probando api": request_description,

#         "helpText": request_help_text,

#     }

#

#     url = "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id)

#

#     return self.post(url, data=data, headers=self.experimental_headers)

# def raise_for_status(self, response):

#     if 400 > response.status_code or response.status_code >= 600:

#         return

#     try:

#         j = response.json()

#         error_msg = j["errorMessage"]

#     except Exception:

#         response.raise_for_status()

#

#     raise HTTPError(error_msg, response=response)

 

# data = _serviceDesk.create_customer_request(service_desk_id=5,

#                                             request_type_id='RRHH',

#                                             values_dict='Probando el Servicio',

#                                             raise_on_behalf_of=None,

#                                             request_participants=None)

 

 

# print(json.dumps(json.loads(data), sort_keys=True, indent=4, separators=(",", ": ")))

 

#Get service

# data= _serviceDesk.get_request_types(5)

# print(json.dumps(data,sort_keys=True,indent=4))

 

data= _serviceDesk.get_my_customer_requests()

print(json.dumps(data,sort_keys=True,indent=4))

Like # people like this
Hana Kučerová Community Leader Nov 24, 2021

Hi @Francisco Alberto Franjul Rodríguez ,

thank you for sharing the code.

According to the documentation when you are trying to work with cloud Service Desk, the authentication should look like this:

service_desk = ServiceDesk(
    url='https://your-domain.atlassian.net',
    username=jira_username,
    password=jira_api_token,
    cloud=True)

So you need to generate API token instead of use your password and then add the parameter cloud = True. Please try. Thank you.

Like jaime_heria likes this

how i can call all ticket service desk?

 

Hana Kučerová Community Leader Dec 26, 2021

Hi @Francisco Alberto Franjul Rodríguez ,

it is not very clear what you mean by "all ticket service desk".

According to the Jira Service Desk module documentation, the only possibility is to get customer requests using 

service_desk.get_my_customer_requests()

(customer is the user, who is used for  authentication).

Like jaime_heria likes this
Since @Francisco Alberto Franjul Rodríguez original post we have managed to connect to ServiceDesk. Our current issue that Oauth 1.0 is being deprecated, making our current code obsolete. 
The documentation we found does not cover scripting with Oauth 2.0.
The code with Oauth 1.0 looks like this, how could we upgrade to Oauth 2.0?
'import os
'import requests
'from flask import Flask
'from flask_restful import Resource, Api

'import json

'url = f"{os.getenv('BASE_URL')}/issue"
'headers = {
    "Accept": "application/json",
    "Content-Type": "application/json"

}

'class JiraIssueCreate(Resource):
    def get(self):
        response = requests.post(
            url,
            headers=headers,
            data=payload,
            auth=(
                os.getenv("JIRA_USER"),
                os.getenv("JIRA_TOKEN")
            )
        )
Hana Kučerová Community Leader Dec 27, 2021

Hi @jaime_heria ,

I'm sorry, but this is something I really don't know. I would recommend you to ask a new question here in the community, so that another people here would be able to help you.

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira Service Management

JSM Jira Automation: How to Send SLA Breached Notifications

Hi Everyone, In   this tutorial,  we will show you how you can monitor an SLA, and send notifications before or after the SLA has been breached.   SLA Threshold Trigger The SLA t...

779 views 5 13
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you