Merging tickets in FreshDesk using Python API

Background : I would like to merge tickets in FreshDesk (for specific conditions - but that’s not important for now ) using Python APIs

Problem Statement: I am unable to merge tickets using below 2 code snippets, as I get runtime error code = 404 (response code)

snippet 1

from freshdesk.api import API

import requests

import json

Set up the API endpoint and authentication credentials

api_key = ‘dummyapikey’

api_password = ‘dummypass’

api_endpoint = ‘https://dummyyy.freshdesk.com/api/v2/tickets/merge

Set up the IDs of the tickets to be merged

ticket_ids = [2, 3]

Merge the tickets

payload = {

‘helpdesk_ticket’: {

‘merged_ticket_ids’: ticket_ids

}

}

headers = {

‘Content-Type’: ‘application/json’

}

print (‘hi1’)

response = requests.put(api_endpoint + str(ticket_ids[0]), auth=(api_key, api_password), headers=headers, data=json.dumps(payload))

#response = requests.put(api_endpoint + str(ticket_ids[0]), auth=(api_key), headers=headers, data=json.dumps(payload))

Check the response status code

if response.status_code == 200:
print(‘Tickets merged successfully’)
else:

print(‘Failed to merge tickets’)

========================================================
snippet 2

from freshdesk.api import API

Freshdesk API credentials

api_key = ‘dummypapikey’
domain = ‘https://dummyyyy.freshdesk.com/
ticket_id_to_merge = 1 # ID of the ticket to merge into another ticket
ticket_id_to_merge_into = 2 # ID of the ticket to merge into

Create an instance of the Freshdesk API

freshdesk_api = API(domain, api_key=api_key)

Merge the tickets

try:
freshdesk_api.tickets.merge(ticket_id_to_merge_into, [ticket_id_to_merge])
print(“Tickets merged successfully!”)
except Exception as e:
print(f"Failed to merge tickets. Error: {str(e)}")

Error when I use snippet 2
Freshdesk has deprecated their V1 API from 1st July, 2018.
For more info, visit https://support.freshdesk.com/support/solutions/articles/231955-important-deprecation-of-api-v1
For more info about freshdesk V2 API, visit Freshdesk
Now python-freshdesk library will by default return V2 API client. You need to migrate your project accordingly.

========================================================

Snippet 2 refers VI API which seems to be deprecated, hence I have used V2 API (in Snippet 1) however its returns 404 response code

Seeking support on the same.

Thanks

1 Like