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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,186
Community Members
 
Community Events
176
Community Groups

bitbucket reports API: unable to process json

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 Feb 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

Atlassian Community Events