You can access most objects in GitHub (users, issues, pull requests, etc.) using either the REST API or the GraphQL API. You can find the global node ID of many objects from within the REST API and use these IDs in your GraphQL operations. For more information, see Preview GraphQL API Node IDs in REST API resources.
Note
In REST, the global node ID field is named node_id. In GraphQL, it's an id field on the node interface. For a refresher on what "node" means in GraphQL, see Introduction to GraphQL.
Putting global node IDs to use
You can follow three steps to use global node IDs effectively:
- Call a REST endpoint that returns an object's
node_id. - Find the object's type in GraphQL.
- Use the ID and type to do a direct node lookup in GraphQL.
Let's walk through an example.
1. Call a REST endpoint that returns an object's node ID
If you request the authenticated user:
curl -i --header "Authorization: Bearer YOUR-TOKEN" http(s)://HOSTNAME/api/v3/user
you'll get a response that includes the node_id of the authenticated user:
{
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false,
"name": "monalisa octocat",
"company": "GitHub",
"blog": "https://github.com/blog",
"location": "San Francisco",
"email"