Using the AddAttachment Web Method

Adds an attachment to the specified business object record.

Request Syntax

Use the following syntax in preparing your request:

FRSHEATIntegrationAddAttachmentResponse

AddAttachment(string sessionKey, string tenantId, ObjectAttachmentCommandData commandData)

Parameters

Provide these parameters in your request:

sessionKey: The session key from the Connect web method.

tenantId: The tenant for which the session key is authenticated.

commandData: A structure containing information about the creation request.

public class ObjectAttachmentCommandData

{

public string ObjectId;

public string ObjectType;

public string fileName;

public Byte[] fileData;

public Boolean ForceSaveInDatabase;

}

Include the following attributes for the ObjectAttachmentCommandData:

ObjectId: The RecID of the new attachment.

ObjectType: The type of the main business object to which this attachment is attached in the object reference notation.

fileName: Name of the file.

fileData: Actual file bytes.

ForceSaveInDatabase: Saves the attachment to the database regardless of client configuration. This attribute is false by default.

Return Value

FRSHEATIntegrationAddAttachmentResponse object, defined as follows:

public class FRSHEATIntegrationAddAttachmentResponse

    {

public string status { get; set; }

public string exceptionReason { get; set; }

    }

The FRSHEATIntegrationAddAttachmentResponse class has the following fields:

status: Provides a status about the state of the connection. The table below contains a full description of the available status values.

exceptionReason: Contains exception information, if the application throws an exception when running this web method.

The following table lists the available status values and describes how to interpret them.

Status

Explanation

Success

Successfully added the attachment to the business object record.

Error

Cannot add the attachment to the business object record. The exception information is stored in the exceptionReason field.

The following are common errors:

The file that is uploaded is a restricted file extension. Please contact your System Administrator for a list of allowed file extensions for upload.

The attachment has a file extension that is not allowed for the specified tenant.

Attachment upload finished unsuccessfully.

The application cannot find the business object record.

The definition for business object <Business Object># was not found.

The specified business object does not exist in the tenant.

Example

The following example reads in a sample image from the local file application of the user, and attaches the file to the specified incident record.

const string fileName = "C:\\Temp\\sample.jpg";

 

using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))

{

using (BinaryReader r = new BinaryReader(fs))

{

byte[] AttachmentData = new byte[fs.Length];

 

for (int i = 0; i < fs.Length; i++)

{

AttachmentData[i] = r.ReadByte();

}

 

ObjectAttachmentCommandData data = new ObjectAttachmentCommandData()

{

ObjectId = "9981FBEBAA8B4EE2820364505855ABC2",

ObjectType = "Incident#",

fileName = "sample.png",

fileData = AttachmentData

};

 

FRSHEATIntegrationAddAttachmentResponse response = frSvc.AddAttachment(authSessionKey, tenantId, data);

if (response.status != "Success")

{

Console.WriteLine("Encountered the following error while adding the attachment to the record: " + response.exceptionReason);

}

}

}