May 8, 2020

Classes SoftLayer_Ticket
Tags ticket

Attach a file to a ticket

Attach a file to a created ticket
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 org.apache.commons.codec.binary.Base64;


public class AttachFileToTicket {

    public AttachFileToTicket() throws IOException {
        // Declare your SoftLayer username and apiKey
        String username = "set me";
        String apiKey = "set me";

        Long ticketId = 10811111L;

        // 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:\\ticketCreated\\ticket.txt";

        // Reading the file in bytes
        File file = new File(path);
        FileInputStream ficheroStream = new FileInputStream(file);
        byte contenido[] = new byte[(int) file.length()];;

        String base64String = Base64.encodeBase64String(contenido);
        byte[] backToBytes = Base64.decodeBase64(base64String);

        // Build SoftLayer_Container_Utility_File_Attachment object
        Attachment newFile = new Attachment();

        // Get Api Client and SoftLayer_Ticket service
        ApiClient client = new RestApiClient().withCredentials(username, apiKey).withLoggingEnabled();
        Ticket.Service ticketService = Ticket.service(client, ticketId);

        try {

            com.softlayer.api.service.ticket.attachment.File result = ticketService.addAttachedFile(newFile);

        } catch (Exception e) {
            System.out.println("Error: " + e);

    public static void main(String[] args) throws IOException {
        new AttachFileToTicket();


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue