we are able to create tickets without attachment through SoftLayer API. We have issues doing same with attachments. We are able to retrieve attachments using SLAPI. We have tried attaching files using rest api with base 64 bit encoding, byte array, utf-8 and ascii, through java. Help us on that.
This is a rest request to create standard ticket with attached files:
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Ticket/createStandardTicket
Method: Post
{
"parameters":[
{
"assignedUserId":112233,
"subjectId":1001
},
"This content is for test",
0, "", "", "",
[
{
"filename":"file.txt",
"data":"test test RCV"
}
]
]
}
Replace: $username, $apiKey and 112233 value with your own information.
In case that you are using SoftLayer API Client for Java, it seems that there is an issue at the moment to create standard ticket with an attached file, I tried different ways, but I didn't have success to upload the file.
However, I can provide a workaround to avoid this issue, try the following script:
package Tickets;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Ticket;
import com.softlayer.api.service.container.utility.file.Attachment;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
/**
* This script creates standard ticket and attach file
*
* Important Manual Page:
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createStandardTicket
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/addAttachedFile
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Ticket
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Utility_File_Attachment
*
* @license <http://sldn.softlayer.com/article/License>
* @authon SoftLayer Technologies, Inc. <sldn@softlayer.com>
* @version 0.2.2
*/
public class CreateStandardTicket {
/**
* This is the constructor, is used to create Standard Ticket, it shows basic
* properties for creating a ticket.
*/
public CreateStandardTicket() {
// Declare your SoftLayer username and apiKey
String username = "set me";
String apiKey = "set me";
// Declare the data of the ticket you wish to submit
Long assignedUserId = new Long(112233);
boolean notifyUserOnUpdateFlag = true;
Long subjectId = new Long(1001);
String title = "New Standard Ticket for Test";
// Declare others parameters of the ticket
String contents = "New content for test";
Long attachmentId = null;
String rootPassword = "";
String controlPanelPassword = "";
String accessPort = "";
String attachmentType = "";
// Declare the name of the file that will upload to the SoftLayer API and the path where the file is located
String filename = "fileTest.txt";
String path = "C:/Users/Test/Pictures/test.txt";
// Get Api Client and SoftLayer_Ticket service
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
Ticket.Service ticketService = Ticket.service(client);
// Build SoftLayer_Ticket object containing ticket information
Ticket newStandard = new Ticket();
newStandard.setAssignedUserId(assignedUserId);
newStandard.setNotifyUserOnUpdateFlag(notifyUserOnUpdateFlag);
newStandard.setSubjectId(subjectId);
newStandard.setTitle(title);
// Build SoftLayer_Container_Utility_File_Attachment object
Attachment newFile = new Attachment();
List<Attachment> attachedFiles = new ArrayList<Attachment>();
attachedFiles.add(newFile);
try {
// Creating standard ticket
Ticket ticketCreated = ticketService.createStandardTicket(newStandard, contents, attachmentId, rootPassword, controlPanelPassword, accessPort, attachedFiles, attachmentType);
ticketService = Ticket.service(client, new Long(ticketCreated.getId()));
// Reading the file in bytes
File file = new File(path);
int length = (int) file.length();
BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[length];
reader.read(bytes, 0, length);
reader.close();
// Build SoftLayer_Container_Utility_File_Attachment object
newFile.setData(bytes);
newFile.setFilename(filename);
// Attaching the file to the ticket
com.softlayer.api.service.ticket.attachment.File result = ticketService.addAttachedFile(newFile);
System.out.println("The ticket was created successfully: " + ticketCreated.getId());
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
/**
* This is the main method which makes use of CreateStandardTicket method.
*
* @param args
* @return Nothing
*/
public static void main(String[] args) {
new CreateStandardTicket();
}
}
As you see in the script, first it creates the ticket, after this, the file is uploaded to the ticket.
I hope it really help you.