Create Ticket in Freshdesk from ServiceNow via API

Elias11
Giga Expert

Hi All

I am stuck and do not know further what todo,

 

I am trying to create a Freshdesk ticket with Attachment via API on Servicenow.

I am using REST API and I was able to create the ticket but without an Attachment.

What I need is to have the attachment also,

I tried a lot of way to do that but It is not working,

In Freshdesk Community or Docu are telling me to use Curl but I dont know if and how Servicenow use curl,

I have the curl code for attachment and it should work but I am using JSON in ServiceNow and it is not working.

Please help.

{
 "attachments[]":["@/Users/***/image001.jpg"]
}

This is my result

{"description":"Validation failed","errors":[{"field":"attachments[]","message":"Unexpected/invalid field in request","code":"invalid_field"}]}

1 ACCEPTED SOLUTION

Elias11
Giga Expert

Hi All

 

I solved it now by myself by creating a Portal Widget instead and use HTML and JQUERY to post an API to Freshdesk with Attachment etc.. Here is my code:

Under Client Controller:
  

     $("button").click(
        function() {
            var yourdomain = 'domainame'; // Your freshdesk domain name. Ex., yourcompany
            var api_key = '****'; // Ref: https://support.freshdesk.com/support/solutions/articles/215517-how-to-find-your-api-key
            var formdata = new FormData();
            formdata.append('description', 'sample description');
            formdata.append('email', 'email@email.com');
            formdata.append('subject', 'Test API subject with att.');
            formdata.append('priority', '1');
            formdata.append('type', 'S');
            formdata.append('status', '2');       
            
            formdata.append('custom_fields[custom_fiel]', 'Custom');       
            
            formdata.append('attachments[]', $('#myFile')[0].files[0]);
                    
            
            $.ajax(
                {
                    url: "https://"+yourdomain+".freshdesk.com/api/v2/tickets",
                    type: 'POST',
                    contentType: false,
                    processData: false,
                    headers: {
                        "Authorization": "Basic " + btoa(api_key + ":x")
                    },
                    data: formdata,
                    success: function(data, textStatus, jqXHR) {
                        $('#result').text('Success');
                        $('#code').text(jqXHR.status);
                        $('#response').html(JSON.stringify(data, null, "<br/>"));
                    },

                    error: function(jqXHR, tranStatus) {
                        $('#result').text('Error');
                        $('#code').text(jqXHR.status);
                        x_request_id = jqXHR.getResponseHeader('X-Request-Id');
                        response_text = jqXHR.responseText;
                        $('#response').html(" Error Message : <b style='color: red'>"+response_text+"</b>.<br/> Your X-Request-Id is : <b>" + x_request_id + "</b>. Please contact support@freshdesk.com with this id for more information.");


                    }
                }
            );
        }
    );

 

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<b>Attachment to be added </b><input type='file' id='myFile' />
<button>Create ticket with attachment</button>
<table cellspacing = '10'>
  <tr>
    <td> <b>Result</b></td>
    <td> <div id = 'result'></div> </td>
  </tr>
  <tr>
    <td> <b>Code</b></td>
    <td> <div id = 'code'></div> </td>
  </tr>
  <tr>
    <td> <b>Response</b></td>
    <td> <div id = 'response'></div> </td>
  </tr>
</table>


View solution in original post

7 REPLIES 7

GB14
Kilo Patron

@Elias11  Have you tried the bidirectional integration? DO you happen to know if a role is required on the freshdesk side to create and update tickets from SN?

Hi 

I have a bidirectional integration just to update the Freshdesk ID in a field in snow, once is created from SNOW. 

It will be a Freshdesk API Rule to do that.

It will be a user in snow which I have added the API Key in the rule on FD to be able to update tickets in SN

 

Regards,

Elias

 

And this will be using 

MichaelTomar
Tera Contributor

To create a Freshdesk ticket with an attachment via API from ServiceNow, you might face challenges with direct JSON formatting for attachments. ServiceNow's REST API capabilities do allow for handling complex requests, including file attachments, though it may not directly use Curl commands. Instead, you should adapt the Curl syntax into ServiceNow's HTTP Request method, focusing on multipart/form-data encoding for attachments. For a more straightforward integration, consider using Skyvia. Skyvia can automate the process, potentially bypassing the complexity of manual API calls for attachments between Freshdesk and ServiceNow.