Hi, I know similar questions have been asked a few times but I can't find a clear answer so I'll ask for my specific scenario.
I'm trying to use the ServiceDesk Plus API to add an attachment to an existing request using C#. What I'm struggling with is how do I specify either where the attachment is on disk or (preferably) provide the attachment as a byte array.
I'm aware of this help page on the old API
Request Operations but I can't get the code in the example there to work - I get a message saying "Error when performing - ADD_ATTACHMENT - null".
I've looked at the v3 API help built into the app that looks like this:
(Sorry, don't have a URL to it).
This make absolute sense except that it doesn't specify how to read a file or provide the attachment content.
I've taken a look at this forum post
here and replicated it in C# with a little snippet of code that looks like this:
- string inputData = "{\"attachment\": {\"request\": {\"id\": \"13737\"}}}";
- string url = string.Format("http://localhost/api/v3/attachments?INPUT_DATA={0}&TECHNICIAN_KEY=XXXX-XXXX", inputData);
- MultipartFormDataContent content = new MultipartFormDataContent();
- StreamContent file = new StreamContent(new System.IO.FileStream(@"C:\Users\Administrator\Desktop\Test Attachment.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read));
- content.Add(file, "filename");
- HttpResponseMessage responseMessage = new HttpClient().PostAsync(url, content).Result;
This leads to a response with the message "No file selected for add attachment".
I also tried the above using "file_name" as the parameter name (as per this
article) but that gave the same result.
So, ultimately the question I'm asking is - using either the old API or the v3 API, when uploading an attachment, how do you specify the file or content of the actual attachment.
Thanks,
Jon
ServiceDesk Plus v 9.3 build 9314.