Unable to send attachment to 3rd party
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:11 AM
We are integrating with Zendesk. As per their process first I need to get the token and I need to pass the token in the request body. I am trying with below code.
(function executeRule(current, previous /*null when async*/ ) {
var file = '';
var token = '';
var sysid = '';
var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^state=4^u_state_substatus=42^u_vendor=2b24fd67db8538d076b9ee71ca96199a");
gr.addQuery("sys_id", current.table_sys_id);
gr.query();
if (gr.next()) {
file = current.file_name;
var r = new sn_ws.RESTMessageV2('rest','Post Attachment');
r.setEndpoint("https://xx.com/api/v2/uploads?filename="+file);
r.setHttpMethod("POST");
r.setRequestHeaders("Content-Type", "image/png");
r.setRequestBody(file);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
token = jsonObject.upload.token;
var ticket = gr.u_vendor_ticket_number;
var ticketUpdate = new sn_ws.RESTMessageV2('int rest','Get token');
ticketUpdate.setEndpoint("https://xx.com/api/v2/requests/" + ticket);
ticketUpdate.setRequestBody('{"request":{"comment":{"body": "Attempting to Add and attachment to the ticket.", "uploads": ["' + token + '"]}}}');
var s = ticketUpdate.execute();
var responseBody1 = response.getBody();
var httpStatus1 = response.getStatusCode();
var jsonObject1 = JSON.parse(responseBody1);
gs.log("Attachment upload status " + httpStatus1);
gs.log("Attachment response body after token" + responseBody1);
}
})(current, previous);
I am getting error as
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:13 AM
Did you try to test it via postman first?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:16 AM
yes, in postaman it is working properly