GitHub API: List a users teams within an organization - github

In GitHub when viewing my organization's user list I'm able to see how many teams a user is a member of.
Clicking on this count shows me which teams a user is in, putting me on the following page:
https://github.com/orgs/my-org/teams?query=%40username
However, I'm trying to achieve the same functionality via the GitHub API, but I've been unable to find an endpoint that lists what teams (within an organization) a user is currently a member of.
One workaround is to loop through all the teams in an organization and get their members list, but this can quickly go through my rate limit, so to be able to do this in one request would be useful.

You can do this with GraphQL API v4 filtering users in teams within an organization with userLogins :
{
organization(login: "my-org") {
teams(first: 100, userLogins: ["johndoe"]) {
totalCount
edges {
node {
name
description
}
}
}
}
}
which gives for instance :
{
"data": {
"organization": {
"teams": {
"totalCount": 2,
"edges": [
{
"node": {
"name": "Employees",
"description": "org employees"
}
},
{
"node": {
"name": "Developers",
"description": "active developers"
}
}
]
}
}
}
}
Source : platform.github.community forum

Unfortunately, GitHub does not yet provide a way to do this.
At the moment, like you suggested, you would have to loop through each team in the organization to get all members within each one, then you would need to loop through all users, and check if the users are members of those teams.
You can increase your rate limit if you use an API token, but the solution is still lousy if you have a large organization.

Heads up!
Providing an invalid/unknown "userLogin" sometimes results in all teams being returned.
Perhaps me doing something wrong, but I opened a ticket with GH about this, so lets see:
https://github.community/t/teams-userlogins-filter-is-not-working-as-expected/206251

Related

Retrieve ALL Github issues of a specific Project using the GraphQL API

I've been trying to retrieve all GitHub issues of a specific project using their GraphQL API.
The problem that i have is that i need to specify in the items a first or last param it doesn't work. Although by specifying one of these params i get only a partition of the issues.
I thought that i could get the first 100, then use pagination and get the other 100 etc until the response is an empty list. From what i read, i cannot find a parameter in the items that defines a page.
What are your thoughts on this? Is there a workaround?
Thanks a lot for your time.
This query seems to work fine and gives page info under items,
query{
organization(login: "microsoft") {
projectV2(number: 559) {
title
items(first: 100) {
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
Output,
{
"data": {
"organization": {
"projectV2": {
"title": "Azure TRE - Engineering",
"items": {
"pageInfo": {
"endCursor": "Njc",
"hasNextPage": false
}
}
}
}
}
}
Tested the query using,
GitHub Explorer

POST request to JIRA REST API to create issue of type Minutes

my $create_issue_json = '{"fields": { "project": { "key": "ABC" }, "summary": "summary for version 1", "description": "Creating an issue via REST API", "issuetype": { "name": "Minutes" }}}';
$tx1 = $jira_ua->post($url2 => json => decode_json($create_issue_json));
my $res1 = $tx1->res->body;
I try to create a jira issue of type Minutes but POST expects some fields which are not available in the issue of type Minutes. The below is the response.
{"errorMessages":["Brands: Brands is required.","Detection: Detection is required."],"errors":{"versions":"Affects Version/s is required.","components":"Component/s is required."}}
I also tried to fetch the schema using createMeta api but don't find any useful info. The below is the response from createmeta.
{"maxResults":50,"startAt":0,"total":3,"isLast":true,"values":[
{
"self":"https://some_url.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=25683&avatarType=issuetype",
"name":"Bug",
"subtask":false},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/12",
"id":"12",
"description":"An issue type to document minutes of meetings, telecons and the like",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=28180&avatarType=issuetype",
"name":"Minutes",
"subtask":false
},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/23",
"id":"23",
"description":"Used to split an existing issue of type \"Bug\"",
"iconUrl":"https://some_url.com:8443/images/icons/cmts_SubBug.gif",
"name":"Sub Bug",
"subtask":true
}
]
}
It looks like there Jira Admin has added these as manadatory fields for all the issuetypes which I came to know after speaking with him. He has now individual configuration for different issue types and am able to create minutes.

Get GitHub Repository Insights via GitHub GraphQL API (v4)

I want to obtain information about the number of times my projects have been viewed, cloned and where the traffic came from (individually).
I can currently view this Traffic information by clicking on the Insights button of the repository (via the web interface).
Is there a schema in the GitHub v4 GraphQL API to retrieve this information?
The closest I got was the following; nodes didn't contain any sort of statistical data:
{
viewer {
repositories(first: 100) {
totalCount
nodes {
name
description
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
// response
{
"data": {
"viewer": {
"repositories": {
"totalCount": 55,
"nodes": [
{
"name": "Repo Name",
"description": "Repo Description"
},
{
...
}
}
}
}
}
Currently it is not possible to retrieve traffic information using GraphQL API (as explained in here).
Alternately you can use REST API v3 as described in GitHub documentation.
Please notice that reviewing traffic requires tokens with push permissions to the desired repositories.

MS Graph REST API checkout user

I've managed to successfully checkout a file using the https://graph.microsoft.com/beta/drives/{driveId}/items/{itemId}/checkout
Now, I'd like to get the information about the user, who actually perform the checkout operation.
It's possible to check if the item is locked:
https://graph.microsoft.com/beta/drives/{driveId}/items/{itemId}?select=*,publication
However, according to DOCs, publication doesn't provide information about the checked user. Without information who locked the file is the whole checkin/checkout logic is useless.
This kind of information could be retrieved via the metadata for an item in a list as demonstrated below:
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{item-id}?expand=fields(select=CheckoutUserLookupId)
Once you get checkout user id (CheckoutUserLookupId field) , user details could be determined via the following endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/lists('User Information List')/items/{CheckoutUserLookupId}
where CheckoutUserLookupId is the user id from the previous request
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{item-id} can't work with folders.
Anyway, drive endpoint "Allows access to the list as a drive" (according to MS Graph Docs). It works with folders as expected.
So I have
get the drive-id: /sites/${siteId}/drives
list root folder: /drives/{drive-id}/items/root/children?select=name,publication
if an item is locked, it's possible to list the activity on the item:
/drives/${idObj.driveId}/items/${idObj.fileId}?select=id&expand=activities
return list of actions:
"activities": [
{
"#odata.type": "#oneDrive.activityEntity",
"#odata.id": "https://xxxxxxxxxx/v2.0/oneDrive.activityEntity2a3649d6-2xxxxx",
"#odata.editLink": "oneDrive.activityEntity2a3649d6xxxxxx",
"#sharePoint.localizedRelativeTime": "0|July 30",
"action": {
"checkout": {}
},
"actor": {
"user": {
"email": "XXX#XXX",
"displayName": "vladimir",
"self": {},
"userPrincipalName": "XXX#XXX
}
},
"id": "XXXXXXXXXXXXXX",
"times": {
"recordedTime": "2018-07-31T04:59:03Z"
}
},
although no user ID at least a have the email....

Facebook API endpoint to get campaigns of a certain objective?

I'm trying to fetch all of my ad campaigns from Facebook whose objective is "WEBSITE_CLICKS" (ie, driving visitors to your site). When I make a GET request against the following:
/act_myaccountid/adcampaign_groups?fields=objective,name
or, using the official Python Ads SDK:
fields = [facebookads.objects.AdCampaign.Field.objective, facebookads.objects.AdCampaign.Field.name]
campaigns = my_user_account.get_ad_campaigns(fields=fields)
I get something that looks like:
{
"data": [
{
"objective": "NONE",
"name": "name1",
"id": "1234"
},
{
"objective": "NONE",
"name": "name2",
"id": "567"
},
I'd like to be able to only get campaigns with that particular objective. Is there a way to do this? I read through the Ads documentation but didn't see anything.
It's not documented as far I've seen but the FB Ads Manager UI allows such filtering which also happens to work in external Graph API calls.
Make a call to the API with a filtering parameter like so:
filtering=[
{
"field":"<FIELD>",
"operator":"IN",
"value":[
"<VALUE>"
]
}
]
For example, your request would be:
/act_myaccountid/adcampaign_groups?fields=objective,name&filtering=[{"field":"objective","operator":"IN","value":["WEBSITE_CLICKS"]}]