Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP 400 and 500 errors but successful after some attempts

Nicolò_Vattai
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2020

Hello,

I have a c++ program that uses nlohman json to parse and construct json data and curl to construct HTTP requests. My goal is to read a task, make a status transition via POST method and add something in the comment. Both the task reading and comment writing work on shell and in program. I was able to work out the shell command for transitioning the task:

curl.exe --user bla.bla@blabla.com:xxxxxxxxx -X POST -H "Content-Type: application/json" -d '{""transition"": {""id"": ""51""}}' https://bla1234.atlassian.net/rest/api/3/issue/AS-10/transitions?expand=transitions.fields

Which works perfectly.  I implemented then the same thing in c++  with curl and that's where the strange things happens. When trying to update I often get HTTP 400 and 500 errors. Continue trying and eventually the post is accepted (see image1). I tried basically to replace every character in my string, at the moment the header and the json are generated like that:

 headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Accept-Encoding: identity");
headers = curl_slist_append(headers, "Content-Encoding: identity");
headers = curl_slist_append(headers, "Content-Type: application/json; charset=UTF-8");
headers = curl_slist_append(headers, "Accept-Charset: utf-8");
.
.
.
transition = "51";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"transition\": {\"id\": \"" + transition + "\"}}")

Apparently adding encoding mitigated a little the problem, however the number of errors before it gets accepted are completely random. Sometimes no error at all sometimes 20 attempts.

Someone an idea?

Annotazione 2020-04-27 171405.png

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2020

Hi Nicolo,

Sorry to hear about this problem.  I understand that you are having some problems trying to get a C++ program to make REST API calls to Jira Cloud consistently.   From the errors you have posted it certainly looks like Jira is seeing an unexpected or illegal character being sent to it somewhere. 

But the fact that this can be run again and not display this error is weird.  You shouldn't have to send the same request multiple times just to have it succeed on occasion.

I would recommend only including the headers you need to make this call work.  I've seen extra headers sometimes cause unexpected results from Jira. Also depending on the endpoint you are called, the headers might be slightly different.

I did some digging on this kind of problem and ran across this thread: https://stackoverflow.com/questions/9254891/what-does-content-type-application-json-charset-utf-8-really-mean

Which would seem to indicate that even if you set the charset=UTF-8 in the header to pass to Jira, that doesn't necessarily seem to ensure that the content your C++ program is sending is actually encoded in that character format.  In which case, I suspect that data being sent could be any one of a number of encoded formats.

The second error message is clearly showing that Jira sees some kind of whitespace character, but not a legal one.  While I'm not much of a coder, I would be interested to learn more details about how this is working from your side.  I suspect that you might have to filter or validate the json before sending this payload to make sure that it's sending characters that Jira will understand.

Regards,

Andy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events