Creating tickets with REST-POST under C#

Subscribe to Creating tickets with REST-POST under C# 6 post(s), 3 voice(s)

 
Schusta 3 post(s)

Hi everyone!

I would like to integrate a bug reporting system right in my C#-application using Assembla ticketing but somehow I can’t manage to create or view the tickets in my space.

I hope someone has some experience with C#/REST and can help me.

Thanks in advance!

Christian Schuster

This is the code that I use to retrieve the tickets:

Uri assembla = new Uri(“http://www.assembla.com/spaces/vcb/tickets/”);
HttpWebRequest request = WebRequest.Create(assembla) as HttpWebRequest;

request.Method = “GET”;
request.Credentials = new NetworkCredential(“Username”, “Password”);
request.Accept = “application/xml”;

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{ StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd());
}

 
Schusta 3 post(s)

Ah I totally forgot to describe the actual problem: I only get a HTTP 200 status code back, no tickets, no 201 CREATE (when attempting to create a ticket).

 
Schusta 3 post(s)

I did some further research and found out that the response-URL that I get with the response “www.assembla.com/user/login” is. I assume that the authentication fails but I have no clue how to fix this problem :(.

 
sdorzak 5 post(s)

Are you passing credentials with your request?
e.g.
proxy.Credentials = new System.Net.NetworkCredential(user, password);

 
sdorzak 5 post(s)

just ignore my previous post – I should read more carefully ;)

here’s the code I used:

            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.assembla.com/spaces/SPACE_NAME/tickets/");
            myRequest.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
            myRequest.PreAuthenticate = true;
            myRequest.Method = "GET";
            myRequest.Accept = "application/xml";
            using (WebResponse myResponse = myRequest.GetResponse())
            using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8))
            {
                Console.WriteLine(sr.ReadToEnd());
            }

 
asultan 1 post

Hi,

I’m trying to achieve the same outcome but I keep getting a WebException saying:

The remote server returned an error: (401) Unauthorized.

I’m assumming that this is because its failing to authenticate my credentials but I’m not sure what I’m doing wrong. I’ve verified the credentials to be correct by logging in through the assembla website with the same credentials and I can view the tickets as well as create new tickets. Is there any setting that needs to be enabled to use the API?

This is the code I’m using:

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.assembla.com/spaces/our_space/tickets/");
myRequest.Credentials = new NetworkCredential("username", "password");
myRequest.PreAuthenticate = true;
myRequest.Method = "GET";
myRequest.Accept = "application/xml";
using (WebResponse myResponse = myRequest.GetResponse())
using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8))
{
    Console.WriteLine(sr.ReadToEnd());
}

Any help would be greatly appreciated.

Forums API