How to test an organization with Github's GraphQL API v4 in Postman?

716 Views Asked by At

Trying to get an orgs private and public repositories in Postman I've attempted:

GET: https://api.github.com/graphql

Under Authorization selected:

Type: Basic Auth

I add my Github username to username and for password per the docs and I place my PAT. For testing purposes I've selected everything for token creation.

Under Body I have:

query:

query ($github_login: String!, $repo_count: Int!) {
  viewer {
    organization(login: $github_login) {
      login
      id
      location
      name
      url
      repositories(first: $repo_count, privacy: PRIVATE, isFork: false) {
        nodes {
          id
          name
          openGraphImageUrl
          createdAt
          stargazerCount
          url
          description
        }
      }
    }
  }
}

variables:

{"github_login": "org-name", "repo_count": 100}

my Status is a 200 OK but my results are not repositories but instead a long listing of null:

"types": [
                {
                    "kind": "INPUT_OBJECT",
                    "name": "AbortQueuedMigrationsInput",
                    "description": "Autogenerated input type of AbortQueuedMigrations",
                    "fields": null,
                    "inputFields": [
                        {
                            "name": "ownerId",
                            "description": "The ID of the organization that is running the migrations.",
                            "type": {
                                "kind": "NON_NULL",
                                "name": null,
                                "ofType": {
                                    "kind": "SCALAR",
                                    "name": "ID",
                                    "ofType": null
                                }
                            },
                            "defaultValue": null
                        },
                        {
                            "name": "clientMutationId",
                            "description": "A unique identifier for the client performing the mutation.",
                            "type": {
                                "kind": "SCALAR",
                                "name": "String",
                                "ofType": null
                            },
                            "defaultValue": null
                        }
                    ],
                    "interfaces": null,
                    "enumValues": null,
                    "possibleTypes": null
                },

In my research I've read:

In Postman how can I get my org repositories with the Github API?

1

There are 1 best solutions below

3
On

The viewer Graphql API returns the user which has been authenticated.

You should instead use the organization API to get the repo list.

Example Query

query ($github_login: String!, $repo_count: Int!) {
    organization(login: $github_login) {
      login
      id
      location
      name
      url
      repositories(first: $repo_count, privacy: PRIVATE, isFork: false) {
        nodes {
          id
          name
          openGraphImageUrl
          createdAt
          stargazerCount
          url
          description
        }
      }
    }
}
{"github_login": "org-name", "repo_count": 100}