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

bitbucket reports API: unable to process json

Douglas Knudsen February 6, 2022

I am trying to post a coverage report into the reports API and getting this response

{"code": 400, "message": "Unable to process JSON"}

This is the cURL with data scrubbed.  A simple data point works, so I know the API can work for me, but when the value field is the below, the API chokes. Without more logs from bitbucket, no idea why.  How can I post a report like this?

curl --proxy http://localhost:29418 --request PUT http://api.bitbucket.org/2.0/repositories/<myuser>/commit/<myhash>/reports/mysystem-001 --header 'Content-Type: application/json' --data-raw '{
"title": "Coverage Report Summary",
"details": "This is the coverage report of the tests run in this pipeline",
"report_type": "COVERAGE",
"result": "FAILED",
"data": [
{
"title": "Coverage Report",
"value": "-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 97.56 | 88 | 100 | 97.26 |
app | 100 | 100 | 100 | 100 |
app.config.ts | 100 | 100 | 100 | 100 |
...ounts/accounts | 100 | 100 | 100 | 100 |
....component.ts | 100 | 100 | 100 | 100 |
...tacts/contacts | 100 | 100 | 100 | 100 |
....component.ts | 100 | 100 | 100 | 100 |
app/core/services | 97.18 | 88 | 100 | 96.96 |
...er.service.ts | 100 | 100 | 100 | 100 |
loggerLevel.ts | 100 | 100 | 100 | 100 |
...le.service.ts | 93.1 | 77.77 | 100 | 92.3 | 37,56
...te.service.ts | 100 | 75 | 100 | 100 | 19
...oard/dashboard | 100 | 100 | 100 | 100 |
....component.ts | 100 | 100 | 100 | 100 |
testing | 100 | 100 | 100 | 100 |
...ing.module.ts | 100 | 100 | 100 | 100 |
testing/mock-data | 100 | 100 | 100 | 100 |
profile-photo.ts | 100 | 100 | 100 | 100 |
profile.ts | 100 | 100 | 100 | 100 |
-------------------|---------|----------|---------|---------|-------------------"
}
]
}'

 

I have tried "type":"TEXT" in teh data node as well, same response.

 

 

 

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 23, 2022

Hello @Douglas Knudsen ,

Welcome to Atlassian Community!

I've reviewed the details you have shared with us and it seems you are receiving this error because the JSON data you are providing in the cUrl command is invalid.

Accordingly to JSON specification, some special characters are not allowed in a JSON string, such as new line characters you are using in data:value field. If you would like to use those characters, you'd have to escape them by using backslash(\) , for example, replacing new line character by \n.

This is not something specific to the Bitbucket API, but on how JSON specification works, so both client and server can understand the data being transferred.

Please find below an example of request using \n instead of new line character in the JSON string value :

curl -X PUT -v -u 'username:app_password' 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/commit/<commit_hash>/reports/mysystem-001' --header 'Content-Type: application/json' --data '{
"title":"Coverage Report Summary",
"details":"This is the coverage report of the tests run in this pipeline",
"report_type":"COVERAGE",
"result":"FAILED",
"data":[
{
"type":"TEXT",
"title":"Coverage Report",
"value":"--------|---------|----------|---------|---------|-------------------\nFile | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s"
}
]
}'

However, I've noticed you are trying to add all the information of your report in the data:value field of the API call, which might not be the best approach. The data section of a report is usually intended to include summary information about the report itself, such as the duration, if it's safe to merge, and some small text data.

If you want to add more granular/detailed data to a given report, my suggestion is to use annotations. Annotations are individual findings that have been identified as part of a report, for example, a line of code that represents a vulnerability. These annotations can be attached to a specific file and even a specific line in that file; however, that is optional. Annotations are not mandatory and a report can contain up to 1000 annotations.

You can refer to the following documentation about the usage of annotations along with your reports :

Hope that helps! Let me know if you have any questions.

Thanks, @Douglas Knudsen

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events