cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
andrewc
Engaged Sweeper
Hello,

EDIT: I've narrowed it down to the filename, example #4 works when I hard code a value.

I'm trying to use the AddTicket API to upload files to Lansweeper but I get a Success=False every time, yet the ticket still gets created in Lansweeper and the file is attached to the ticket. The Message from the response is: "Something went wrong. The creation was unsuccessful -> Length cannot be less than zero.\r\nParameter name: length". I get a Success=True if I hard code values. I just change the header string to switch between a failure/success.

Does anyone know what's causing this?
Is this a configuration issue?

Thanks.

Examples of what I see:

1. string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, "readmetxt", "readme.txt", "text/plain");

Success=True
header=
------------4efd4a7da92e4e66b75f8a5b2f64303d
Content-Disposition: form-data; name="readmetxt"; filename="readme.txt"
Content-Type: text/plain

2. string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, attachment.Replace(".", string.Empty), attachment, MimeMapping.GetMimeMapping(HostingEnvironment.MapPath("~/Content/Uploads/") + attachment));

Success=False
header=
------------f9de5cb908ec473eaa911b3e66d98823
Content-Disposition: form-data; name="app_offline7htm"; filename="app_offline7.htm"
Content-Type: text/html

3. Same as above, string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, attachment.Replace(".", string.Empty), attachment, MimeMapping.GetMimeMapping(HostingEnvironment.MapPath("~/Content/Uploads/") + attachment));

Success=False
header=
------------4d9b56d68fd2441eaba50c6c439810dc
Content-Disposition: form-data; name="modelxlsx"; filename="model.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

4. string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, attachment.Replace(".", string.Empty), "random.random", MimeMapping.GetMimeMapping(HostingEnvironment.MapPath("~/Content/Uploads/") + attachment));

Success=True
header=
------------1004f0e9e5e74348b0c310390c9fb0ef
Content-Disposition: form-data; name="readmetxt"; filename="random.random"
Content-Type: text/plain
1 REPLY 1
petergrigg
Engaged Sweeper
Getting the exact same issue, and after looking at the tables, it appears Lansweeper allowed the same 2 files I was working on a number of times on different tickets, but after that, it started to get the "length is zero" error, even though it still created a ticket. It also seems to recognize that these are the same files, even though to get the error to go away, I slightly changed the Name and the fileID in the HTBLAttachements table stayed the same, which tells me that Lansweeper has figured out it is the same file and doesn't waste space storing it somewhere.

I'm guessing there is some problem with that logic.

For now, I will post the original ticket without attachments, just to get a good ticket number, and then add the attachments using the addnote api. If that fails, I will instruct the users to add the attachments manually to the ticket.