I'd like to populate my JIRA database programmatically, by POSTing CSV data via the API. I have the URL and authentication working, but I consistently get 400 errors: "Bad Request". My guess is that I'm missing some required field in the payload:
{
"comment": "test",
"self": "https://jira.mycompany.com/rest/api/latest/issue/12345",
"started": "2015-12-09T17:29:14.698-0500",
"timeSpent": "1 s",
"timeSpentSeconds": "1"
}
The documentation has an example, but it includes some fields which appear to be inapplicable to a POST, such as the worklog ID - which surely must be created by the server, not the client. The query parameters are all optional.
One user claims to have success with just three fields: comment
, started
, and timeSpent
. I still get a 400 with just those fields. Another did the same, after adjusting the time format; I'm matching his or her format. Other users can POST using comment
, started
, and timeSpentSeconds
.
A common problem has been setting content-type appropriately; I believe I have that covered, as I get a 415 "Unsupported Media Type" if I use a type other than "application/json".
I hear that there's a specific product required to use the API for writing (as opposed to reading, which works fine). If we were missing that license, I would expect to get an error message to that effect, however.
Here's the code, with a little verbosity for debugging:
// Initialize various parameters
string url = baseUrl + "issue/" + issueKey + "/worklog";
var rawContent = // Double-quote and concatenate parameters, and wrap them in curly brackets
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", encodedCreds);
var content = new StringContent(rawContent, Encoding.UTF8, "application/json");
// Using POST gives a 400 Bad Request error; are we missing a required field?
var task = client.PostAsync(url, content); task.Wait();
var response = task.Result;
Am I missing a required field? There's no change in the error returned if I POST with no content, or with invalid field names. It would be nice if JIRA would deign to tell me what fields it is expecting but not getting, or getting but not expecting.
rawContent
or have you purposefully removed it? – AstrobiologyrawContent
is non-trivial, and I didn't want to clutter the code example. It generates the text shown before the code, in the top half of the question. – Vaginismus