- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 04:34 AM
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"}]}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 12:04 AM
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>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 05:31 AM
HI,
Try this:
https://community.servicenow.com/community?id=community_question&sys_id=de244af1db27f3444819fb243996...
If this doesnot work then create a scripted rest API.
Thanks,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 06:38 AM
thanks for your quick reply.
those are all advice how to add attachment in Servicenow but what I need is from Servicenow to Freshdesk a 3rd Party and this Freshdesk as far as I understood it accept curl for Attachment,
Elias

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 08:24 AM
Oh,
This is something your Freshdesk teams needs to tell you, how they handle this incoming traffic.
https://developers.freshdesk.com/api/#create_ticket_with_attachment
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 12:04 AM
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>