Just in. Im about to contact the support but thanks there is the detailed guide here.
Folks,
Please bookmark the link : https://github.com/freshdesk/fresh-samples . We have added a lot more API samples here. In case if something that you're looking for is not available in the link, drop us a note here . We'll work on the sample and get it added to our repository.
Cheers!
Created fork: https://github.com/nafanz/fresh-samples
Left only Python, of the features:
* First, I translated all the code into syntax Python 3.5.2 (since it is found in most Linux distributions)
* I made a separate file for storing authorization data, so as not to duplicate the domain name and api key in each script
Since I am not a developer, I will be glad to hear comments and corrections
Instead of using the provided samples provided by Freshdesk, here's a sample for inserting a ticket with attachments (from azure blob storage) which uses HttpClient and default HttpContent-derived objects in stead of implementing all that finicky stream handling yourself:
// constructor: _httpClient = new HttpClient { BaseAddress = new Uri(_config.BaseAddress) // http://domain.freshdesk.com/ }; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", $"{_config.ApiKey}:dummypassword".ToBase64()); // add ticket method: var requestContent = new MultipartFormDataContent { // for StringContent the name *must* have quotes also, otherwise the API will complain about invalid names { new StringContent(ticket.EmailAddress, Encoding.UTF8), "\"email\"" }, { new StringContent(ticket.UniqueId, Encoding.UTF8), "\"unique_external_id\"" }, { new StringContent(_config.DefaultSubject, Encoding.UTF8), "\"subject\"" }, { new StringContent(ticket.Description, Encoding.UTF8), "\"description\"" }, { new StringContent(_config.DefaultStatus.ToString(), Encoding.UTF8), "\"status\"" }, { new StringContent(_config.DefaultSource.ToString(), Encoding.UTF8), "\"source\"" }, { new StringContent(_config.DefaultPriority.ToString(), Encoding.UTF8), "\"priority\"" }, { new StringContent(_config.DefaultGroupId.ToString(), Encoding.UTF8), "\"group_id\"" }, { new StringContent(_config.DefaultType, Encoding.UTF8), "\"type\"" } }; var container = _storageContext.StorageContainer; // Azure Blob Storage container reference // ticket.Images are a list of strings which point to each image in azure blob storage foreach (var image in ticket.Images) { var blob = container.GetBlockBlobReference(image); var content = new StreamContent(await blob.OpenReadAsync()); content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); requestContent.Add(content, "attachments[]", $"{image}.jpg"); } var message = new HttpRequestMessage(HttpMethod.Post, "api/v2/tickets") { Content = requestContent }; var response = await _httpClient.SendAsync(message); var result = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode();
Biggest issue I encountered is that Freshdesk requires extra quotes in the name of each StringContent. If you do not include those, the API will complain that invalid fields (e.g "email\r\n") are included in the request body, since it adds the CRLF to name of the field if it isn't wrapped in quotes...
Would appreciate if you add an example using your Query API for PHP?
Hello ladies and gents.
I'm working on a collection of Python scripts using the Freshdesk API, which will be helpful for anyone who is just getting started with the API. You may be able to skip some of the learning curve by seeing how these scripts work.
https://github.com/DavePlaysNotes/Freshdesk_scripts
So far I have scripts for:
Hi
Can anyone share a Python script which will read the last mail/reply/update from Freshdesk ticket.
Thanks in advance.
Dhananjay K.
@Dhananjay, you can view conversations on a ticket using the tickets/[ticket_ID]/conversations endpoint. Bear in mind though that this does not include the first message on a ticket, which is saved instead as the ticket description.
If you enter your details and run the script below it will pull the list of conversations for that ticket. The final line selects slice [-1] from the response, which is the most recent note on the ticket. To see other meta data about the note just remove the ['body_text'] slice after that, which I've put in so that you can see the specific message.
I hope that helps!
import requests as r import json desk_name = 'your_Freshdesk_account_name' # This is your Freshdesk URL without '.freshdesk.com' on the end. # eg: if your full URL is 'megashop.freshdesk.com' use 'megashop' auth_details = ("your_API_key", "your_Freshdesk_password") # Your Freshdesk API key is in your Freshdesk profile: https://support.freshdesk.com/support/solutions/articles/215517-how-to-find-your-api-key # A password must be provided but it does not appear to be verified. # For security's sake, you can leave the password as it is or enter in some humourous nonsense for your own satisfaction. ticket_ID = 12345 #this is the ticket number you want to query #no need to enter anything after this point URI = "https://" + desk_URL + ".freshdesk.com/api/v2/tickets/" + ticket_ID + "/conversations" query = r.get(URI, auth = auth_details) query.json()[-1]['body_text']
Hi Dave,
It is working fine now. Some modifications as required were done. Thanks lot for your support.
Thanks.
Dhananjay K
Hi,
I am having trouble getting a JSON file of Data Export in python.
I have tried with:
r = requests.get("https://" + desk_URL + ".freshdesk.com/reports/schedule/download_file.json?uuid=eeeaf794-620e-442f-9176-d762a729804b", auth = (api_key, password))
And r.status_code returns '500'.
How can we export tickets data with python?
The API v2.0 doesn't provide enough fields for us, so we want to export through "Data Export".
Thank you in advance.
Start your 21-day free trial. No credit card required. No strings attached.
Start Free Trial
Vijay Shankar
Hi All
We've added our Sample APIs here - https://github.com/freshdesk/fresh-samples/tree/master/Ruby_api_samples
Please use this Forums to raise all your queries regarding Freshdesk API and you may also share your Ruby or PHP API samples here
thanks
Vijay
6 people have this question