Unable too add attachment when comment using REST API

Hi

I have a problem in my webclient when i try to include an attachment in my request
I’m using RestSharp to create and send the request

and here is the code

            var client = new RestClient();
            client.BaseUrl = new Uri("localhost/REST/1.0/ticket/" + ticketId + "/comment");

            var request = new RestRequest();
            request.AddParameter("user", user);
            request.AddParameter("pass", pwd);
            request.AddParameter("content", "id: " + ticketId + "\nAction: comment\nText: This is a test comment\nAttachment: test.PNG");
            request.AddFile("attachment_1", @"C:\Users\user\Desktop\test.PNG");


            var asyncHandler = client.ExecuteAsync(request, r =>
            {
                if (r.ResponseStatus == ResponseStatus.Completed)
                {
                    Console.WriteLine(r.Content);
                }
            })

the response i get back is

RT/4.2.5 400 Bad Request

# No attachment for test.PNG

Without the attachment included the code work as expected and RT register a comment

i’m at a loss here and appriciate any help

Kind regards
John

Found out the solution myself, was nothing wrong at the RT side, Instead i was making the assumption that if commenting without attachment worked commenting with attachment would work without any changes.

There i was wrong
Commenting without attachment is possible with just an GET request
so with my code i was always sending GET request hence no attachment was found.

when i added this line and forced RestSarp to use POST it worked

        request.Method = RestSharp.Method.POST;

My working code

        var client = new RestClient();
        client.BaseUrl = new Uri("localhost/REST/1.0/ticket/" + ticketId + "/comment");

        var request = new RestRequest();
        request.Method = RestSharp.Method.POST;
        request.AddParameter("user", user);
        request.AddParameter("pass", pwd);
        request.AddParameter("content", "id: " + ticketId + "\nAction: comment\nText: This is a test comment\nAttachment: test.PNG");
        request.AddFile("attachment_1", @"C:\Users\user\Desktop\test.PNG");


        var asyncHandler = client.ExecuteAsync(request, r =>
        {
            if (r.ResponseStatus == ResponseStatus.Completed)
            {
                Console.WriteLine(r.Content);
            }
        })