400 / 500 error adding worklog in Jira REST API

852 views Asked by At

I am ready to bang my head off a brick wall so would greatly appreciate any input on this. I am getting the above mentioned errors when I try to add a new worklog. The code to try and add the worklog....

// convert worklog to json string
JavaScriptSerializer serializer = new JavaScriptSerializer();
string data = serializer.Serialize(worklog);

// set up the web request
HttpWebRequest request = WebRequest.Create(baseUrl) as HttpWebRequest;
request.ContentType = "application/json";
request.Method = method;
request.ContentLength = data.Length;

// Authorize user
string base64Credentials =     GetEncodedCredentials(_currentEmployeeUsername_currentEmployeePassword);
request.Headers.Add("Authorization", "Basic " + base64Credentials);
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}

// return the response
HttpWebResponse response = request.GetResponse() as HttpWebResponse;

The worklog object I am serializing is as follows...

public class WorkLog
{
    public string comment;

    public DateTime started;

    public string timeSpent;
}

The above code gave me a 500 Internal Server error. I've had a browse around lots of questions asked previously and guessed the issue was with the data I am sending. So I've tried a number of variations, one example which had been marked as an answer suggested the following:

"{\"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"author\": {\"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"name\": \"cbourke\", \"displayName\": \"cbourke\", \"active\": false }, \"updateAuthor\": { \"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"name\": \"cbourke\", \"displayName\": \"cbourke\", \"active\": false }, \"comment\": \"Testing.\", \"started\": \"2012-02-15T17:34:37.937-0600\", \"timeSpent\": \"3h 20m\", \"timeSpentSeconds\": 12000, \"id\": \"1234\"}"

So I replaced my 'data' with this (adding in my own values). And that gives me the 400 Bad request error. I would be eternally grateful for suggestions as to what I can do to rectify this. I am sure I am doing something silly here but cannot seem to find it / figure it out.

Thanking you!

0

There are 0 answers