Upload Attachment to Incident by Using HTTP
Use this API to upload binary or text attachments to cases by using HTTP.
URI
http://[host]/api/juniper/servicenow/incident-management/incidents/{id}/uploadAttachment (HTTP method = POST)
URI Parameters
Parameter | Type | Required | Description |
---|---|---|---|
id | Integer | Yes | ID of the incident to which attachments are to be uploaded |
Consumes
Multipart data
You need to pass the attachment files in the HTTP POST method as multipart data. In the HTTP post method, MultipartRequestEntity should be set as RequestEntity. The MultipartRequestEntity parameter should be instantiated using FilePart. FilePart (org.apache.commons.httpclient.methods.multipart.FilePart) should contain the details (such as the file name) of the attachment file.
Produces
None
Input
Sample Input File
String addURL = "http://[host]/api/juniper/servicenow/case-management/cases/524417/uploadAttachment String user = "super"; String pwd = "juniper123"; HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setStaleCheckingEnabled(true); PostMethod postMethod = new PostMethod(addURL); try {postMethod.addRequestHeader("Authorization", "BASIC" + " " + new String(Base64.encodeBase64(new String(user + ":" + pwd).getBytes("UTF-8")))); postMethod.addParameter("alias-name", "sn-partner"); String fileName = "/var/tmp/test.txt"; File file = new File(fileName); File file1 = new File("/var/tmp/test1.txt"); FilePart filePart; filePart = new FilePart(file.getName(), file); Part[] fileParts = new Part[2]; fileParts[0] = filePart; filePart = new FilePart(file1.getName(), file1); fileParts[1] = filePart; postMethod.setRequestEntity(new MultipartRequestEntity(fileParts, postMethod.getParams())); httpClient.executeMethod(postMethod); System.out.println(postMethod.getResponseBodyAsString()); }catch(Exception e){ e.printStackTrace(); } }