I'm trying to list all the users in Jira using the REST API, I'm currently using the search user feature using GET : https://docs.atlassian.com/jira/REST/server/#api/2/user-findUsers
The thing is it says that the result will by default display the 50 first result and that we can expand that result up to 1000. Compared to other features available in the REST API, the pagination here is not specified.
An example is the group member feature : https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup
Thus I did a test and with my test Jira filled with 2 members, tried to get only one result and see if there was some sort of indication referring to the rest of my result.
The response provided will only give the results and no ways to get to know if there was more thatn 1000 (or 1 in my example), it's maybe logical but in the case of an organization with more than 1000 members, listing all the users doing this : http://jira/rest/api/2/user/search?username=.&maxResults=1000&includeInactive=true will only give at most 1000 results.
I'm getting all the users no matter what their name are using . as the matching character.
Thanks for your help!
What you can do, is to calculate manually the number of users.
Let's say you have 98 users in your system.
First search will give you 50 users. Now you have an array and you can get the length of that array which is 50.
Since you do not know if there are 50 or 51 users, you execute another search with the parameter &startAt=50.
This time the array length is 48 instead of 50 and you know that you've reached all the users in the system.
From speaking to Atlassian support, it seems like the user/search endpoint has a bug where it will only ever return the first 1,000 results at most.
One possible other way to get all of the users in your JIRA instance is to use the Crowd API's /rest/usermanagement/1/search endpoint:
curl -X GET \
'https://jira.url/rest/usermanagement/1/search?entity-type=user&start-index=0&max-results=1000&expand=user' \
-H 'Accept: application/json' -u username:password
You'll need to create a new JIRA User Server entry to create Crowd credentials (the username:password parameter above) for your application to use in its REST API calls:
Go to User Management.
Select JIRA User Server.
Add an application.
Enter the application name and password that the application will use when accessing your JIRA server application.
Enter the IP address, addresses, or IP CIDR block of the application, and click Save.
Related
I am using Keycloak API and I have a use case where I need to get the number of members in a group, before fetching all users.
Unfortunately, both endpoints GET /{realm}/groups/{id}/members and GET /{realm}/groups/{id} do not return such information.
The API doc on https://www.keycloak.org/docs-api/5.0/rest-api/index.html does not seem to indicate how we can get the count.
So, how we can get this information using the Keycloak API ?
Unfortunately, one does not have an endpoint like GET /{realm}/groups/{id}/members/count like one has for the number of groups (i.e., GET /{realm}/groups/count).
What you would need to do, is to define max query parameter to -1 so that you are sure to get all the members using the endpoint GET /{realm}/groups/{id}/members and then just count the number of members on the json response. Of course, this is a sub-optimal approach, but the only one using the API as it is.
I have provided a complete script that automatizes this processes in the following repo.
As mentioned by #dreamcrash, you need to count that from the response of GET /{realm}/groups/{id}/members.
I am using jq.. then my script is:
curl .... ${url}/${realm}/groups/${id}/members | jq '. | length'
I tried to leverage the solution described in this post using fiddler : How to change change Kibana saved search (Discover) with a REST request?
Also I had a look at: https://discuss.elastic.co/t/export-saved-objects-via-rest-api/72028/2
My problem is that even though the json returned by my get rest request has the right value for the number of definitions, it does not embed them all (only 10 out of 34 search definitions), is there like a index + count option for fetching all of them.
Ok just found a workaround, actually, I should have thought about that before...
Here is what I have done, basically listened to the queries from the browser using fiddler (using the https decrypt option) on:
Settings tab
Saved objects
Searches
It seems that there is a size parameter that I was not really aware of (like I said in my initial post, thought about an index + count / limit like in any db system)
POST my_kibana_url/elasticsearch/.kibana/visualization/_search?size=100 HTTP/1.1
{"query":{"match_all":{}}}
And look at the count value to check whether the sizes of all the requests accumulated is matching that number.
using New Relic Rest API v2, is there a way to fetch all associated labels on a sever? i.e. I have the server ID, but I want the labels attached to it? Just like you would in AWS EC2 Tags or Chef Tag attributes. I've checked their API docs, but I haven't found anything relevant yet... Thanks!
Probably not with out a little coding. This command:
curl -X GET 'https://api.newrelic.com/v2/labels.json' \
-H 'X-Api-Key:{api_key}' -i
will return all the labels on the account. Part of the output returned contains a "links" section for each label that will list the applications and servers the label is applied to. It will appear like this (in part) showing a single server, in this case:
"links": {
"applications": [],
"servers": [
5980960
]
You would have to 'walk' through the list of labels returned by that request, looking for the server ID of the one you are interested in. Remember that the output is paginated so you you may have more than one page to investigate.
This would be worth contacting New Relic support and suggesting a Feature Request.
It is my first time using the Github API, sorry if this is a stupid question. I did a short search for location:Germany, and got 39,063 users. I want to create a list of all the 39,063 usernames and tried this command:
curl -i https://api.github.com/search/users?q=location%3AGermany | grep login
However this returns only 30 hits.. Could anyone give me some advice, or guide me to the right resources?
You will have to make additional requests for other pages:
Pagination
Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. For some resources, you can also set a custom page size up to 100 with the ?per_page parameter. Note that for technical reasons not all endpoints respect the ?per_page parameter, see events for example.
$ curl 'https://api.github.com/user/repos?page=2&per_page=100'
Note that page numbering is 1-based and that omitting the ?page parameter will return the first page.
For more information on pagination, check out our guide on Traversing with Pagination.
For the Marketing API, I know that I'm able to make one call to retrieve all of the adsets from a certain account along with their insights, but am I able to specify the date_preset for the insights edge in that same call?
For example, the following gives me lifetime insights stats:
/v2.4/{accountID}/adcampaigns?fields=insights
To be clear - I know this is possible to retrieve by making separate calls for each adset id (where I know I can specify the date_preset); instead, I'd like to do this via the call where I get a long list of the ad sets plus their insights details in one go.
Yes this is possible using query expansion, however you probably should not do it in this anyway.
Using query expansion results in multiple requests being executed in one HTTP call, in this case one to get all the adcampaigns, and then N requests where N is the number of adcampaigns returned. This will in turn affect your rate limiting.
The most efficient way to request all insights for all adcampaigns (ad sets) is instead to request them at the account level, specifying aggregation level:
/v2.4/act_{ADACCOUNT_ID}/insights?date_preset=last_7_days&level=campaign
This requires just 1 request, or the number of requests to retrieve the total number of pages.
If you really want to achieve this with query expansion, you can do the following for example:
/v2.4/act_{ADACCOUNT_ID}/adcampaigns?fields=insights.date_preset(last_30_days).time_increment(all_days)
You can see the parameters to insights that would normally be query parameters of the form param_name=param_value are now in the form of param_name(param_value).
To specify the date_preset , here is the correct format . Its important to use insights as edge to get the date_preset filtering .
/v2.10/act_{ADACCOUNT_ID}/insights?fields=impressions,clicks,ctr,unique_clicks,unique_ctr,spend,cpc&date_preset=last_3d
The above one is tested with latest Graph Api version(2.10) as of now . FOr more info related to the date_preset values refer to there api docs .
https://developers.facebook.com/docs/marketing-api/insights/parameters