Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

HttpClient (C#) to create Work Log Always Returns 500 (Internal Server Error)

terryaney November 13, 2014

I'm trying to issue a POST to create a worklog to no avail.  I've tried using a HttpWebResponse (from this sample) which didn't work (same error) and I'm now using WebClient (from this sample)

My data I'm sending is:

{
  "timeSpent": "25m",
  "started": "2014-11-13T01:41:46.8508000-0600",
  "comment": "Logged via webhook"
}

My code is basically the following:

where queryInfo is object with property values of {{ Url = "issue/{{issueId}}/worklog", Data = JObject.FromObject( new {{ .. }} ) }}

using ( var client = new HttpClient() )
{
	client.BaseAddress = new Uri( @"https://benefittech.atlassian.net/rest/api/2/" );
	client.DefaultRequestHeaders.Accept.Clear();
	client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
	client.DefaultRequestHeaders.Add( "Authorization", "Basic " + Convert.ToBase64String( Encoding.Default.GetBytes( "myUser:myPassword" ) ) );

	if ( queryInfo.Data != null )
	{
		var response = await client.PostAsJsonAsync( queryInfo.Url, queryInfo.Data );
		response.EnsureSuccessStatusCode();
		var url = response.Headers.Location;
		Console.WriteLine( string.Format( "POST Response for {0}: Url={1}", queryInfo.Url, url ) );
	}
}

And I always get "500 (Internal Server Error)".  Any suggestions on how to debug?  Note that I've successfully used HttpClient (and the header/address stuff) to do a GET and receive correct information.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
terryaney November 13, 2014

Thanks for the info. I tried with { "timeSpent": "25m", "started": "2014-11-13T02:34:29.000-0600", "comment": "Logged via webhook" } and now I get 400 (Bad Request). :(

0 votes
Rudie November 13, 2014

Yeah, I think the date format has to be literally "YYYY-MM-DDTHH:MM:SS.000+TZTZ" so in your case: "2014-11-13T01:41:46.000-0600" -- only the seconds decimals changed. Try that.

TAGS
AUG Leaders

Atlassian Community Events