How to return the history of types from a certain period?

I’m retrieving history from the last 5 months of code smells, bugs and vulnerabilities however I can’t pull all this data and the data looks inconsistent with what I already have in my database. I’m trying to make a request to the Sonar API, using this URL: https://{empresa}/api/issues/search?&author={user_email}&ps=1&facets=types&createdAt=2021-12-14. When I use this url, I get this request response:

However, on this day, I can 6 code smells in another API query, however in this call to this API I get 0. Why do I get this inconsistent data in the request response?

Hey @Felippe_Correa_Lima!

Thanks for sharing this with us.

As a first step, could you indicate what is the other API you’re calling? (in which you’re getting 6 code smells).

Kind regards,

1 Like

This is the URL which i getting 6 code smells: https://{empresa}/api/issues/search?&author={user_email}&ps=1&facets=createdAt&createdAfter=2021-12-01&createdBefore=2021-12-15&types=CODE_SMELL.

print the response:


1 Like

Hey @Felippe!

The createdAt filter that you’re using is time specific. An example value would be 2017-10-19T13:00:00+0200. You can find more specifics on the Web API Documentation at https://{empresa}/web_api/api/issues/search.

An important distinction: the createdAt filter is time specific, but the facet is not. Therefore, if you use the facet, you will get aggregated totals for a date (and not a time).

The reason why the endpoint is not returning 6 code smells is because there is no matching time being provided.

If you’re looking for day totals, grouped by issue type, you would instead need to use the second endpoint you mentioned, which uses createdAfter and createdBefore:

  • https://{empresa}/api/issues/search?author={user_email}&ps=50&facets=createdAt&createdAfter=2021-08-01&createdBefore=2022-01-30&types=CODE_SMELL will get you all the code smells in the last 5 months for a given author. In the payload, you can see how many there are in total (paging/total fields). If you need this data drilled down by day, the createdAt facet will provide you this.

  • https://{empresa}/api/issues/search?author={user_email}&ps=50&facets=createdAt&createdAfter=2021-08-01&createdBefore=2022-01-30&types= BUG will get you all the bugs in the last 5 months for a given author.

  • https://{empresa}/api/issues/search?author={user_email}&ps=50&facets=createdAt&createdAfter=2021-08-01&createdBefore=2022-01-30&types= VULNERABILITY will get you all the vulnerabilities in the last 5 months for a given author.

I hope this clarifies, otherwise feel free to ping me again on this thread!


That’s question in specificy i get resolved. Thank you for help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.