REST Attachments

This is an example using DocStar but the BO’s are the same just use UploadFile instead of DocStarUploadFile

//Read file from Disk into a byte array
Byte[] bytes = File.ReadAllBytes(x);
                        String fileData = Convert.ToBase64String(bytes);
//Create the File Object to be uploaded to Epicor 
                        var file = new
                        {
                            fileName = System.IO.Path.GetFileName(x),
                            data = fileData,
                            docTypeID = "PGOrderD",
                            parentTable = "UD103",
                            metadata = new
                            {
                                _Author = "Epicor PG Importer",
                                _TableName = "Ice.UD03",
                                _TableSysRowID = sysRowID
                            }
                        };
//Upload the file using the Attachment BO
var addedDocStarFile = EpicorRest.DynamicPost("Ice.BO.AttachmentSvc", "DocStarUploadFile", file);

//Create the Epicor XFileRef
var xFileRef = new { Company = company, XFileName = addedDocStarFile.ds.ToString(), XFileDesc = file.fileName, DocTypeID = "PGOrderD" };
var addedXRef = EpicorRest.DynamicPost("Ice.BO.XFileRefSvc", "XFileRefs", xFileRef);

// Once the XFileRef exists attach it to a UD103 record.
var UD103Attch = new
                        {
                            Company=companyID,
                            Key1=key1,
                            Key2 = key2,
                            Key3 = key3,
                            Key4 = key4,
                            Key5 = key5,
                            addedXRef.XFileRefNum,
                            FileName = addedXRef.XFileName,
                            DrawDesc = $"{key1}-{key2}-{key3}-{key4}",
                            DocTypeID = file.docTypeID,
                            ForeignSysRowID = sysRowID,
                            RowMod = "A"
                        };
dynamic newUDAttch = EpicorRest.DynamicPost("Ice.BO.UD103Svc", "UD103Attchs", UD103Attch);
5 Likes