1. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you or to your Kayako. You can visit the forums for the new Kayako here.

Adding second attachment to ticket fails?

Discussion in 'Developing, APIs and extending' started by bergsj, Jul 22, 2012.

  1. bergsj

    bergsj Member

    Hi,

    I have this C# code:

    Code:
            private void CreateTicketAttachment(IEnumerable<TicketAttachmentInfo> attachments, Ticket ticket)
            {
                foreach (var attachment in attachments)
                {
                    var ticketAttachmentRequest = new TicketAttachmentRequest()
                    {
                        Contents = ConvertFileToBase64(attachment.TempFileName),
                        FileName = attachment.FileName,
                        TicketId = ticket.Id,
                        TicketPostId = ticket.Posts.Max(p => p.Id)
                    };
                    try
                    {
                        if (ticketAttachmentRequest.IsValid(RequestTypes.Create))
                        {
                            _kayakoClient.Tickets.AddTicketAttachment(ticketAttachmentRequest);
                        }
                    }
                    catch (InvalidOperationException invOp)
                    {
                        Message.Show(string.Format("AddTicketAttachment InvalidOperation: {0}", invOp.Message), MessageType.Error);
                    }
                    catch (ArgumentException argEx)
                    {
                        Message.Show(string.Format("AddTicketAttachment ArgumentException: {0}", argEx.Message), MessageType.Error);
                    }
                    catch (Exception ex)
                    {
                        Message.Show(string.Format("AddTicketAttachment exception: {0}", ex.Message), MessageType.Error);
                    }
                    finally
                    {
                        File.Delete(attachment.TempFileName);
                    }
                }
            }
    Sometimes the attachment is added , but most of the times when adding I get this Exception:

    {"There is an error in XML document (1, 2)."}
    Looking at the inner exception I see this: {"<div xmlns=''> was not expected."}

    BTW: I am using the C# wrapper library.

    Any help would be appriciated.
    Thanks!
     
    jamra likes this.
  2. bergsj

    bergsj Member

    I have been digging around and it seems to me that the problem occurs when the function of converting a file to a base64 string returns a string with slashes. This will proberly terminate the XML command to the REST api or something.
    The base64 encoding works fine (tested this with the online tool [http://www.motobit.com/util/base64-decoder-encoder.asp]).
    Could this be a bug in the C# wrapper or the REST api?
     

Share This Page