You can get global Global node IDs of objects via the REST API and use them in GraphQL operations.
In this article
Putting global node IDs to use
1. Call a REST endpoint that returns an object's node ID
2. Find the object type in GraphQL
3. Do a direct node lookup in GraphQL
Using global node IDs in migrations
You can access most objects in Scope help you query about specific Scope objects (users, groups, scenarios, etc.) using either the REST API or the via the Scope GraphQL API. With a recent update, you can find the global node ID of many objects from within
You can get global node IDs from the REST API and use these IDs in your GraphQL operations, and vice versa.Note: In /or webhooks.
In REST, the global node ID field is named node_id
, and in webhooks, the global node ID field is named resource_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."
In this article
Table of Contents |
---|
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
, receive a webhook that supplies aresource_id
for an object, or execute a GraphQL query that returns anid
for an object.Find the object's type in the GraphQL reference docs.
Use the ID and type to do a direct node lookup in GraphQL.
Let's walk through an example.
1.
...
Execute a
...
GraphQL query that returns an
...
If you request the authenticated user:
...
id for an object
While Exploring the Graph, execute the following query
Code Block |
---|
query {
viewer {
organization {
groups {
nodes {
id
}
}
}
}
} |
you'll get a response that includes the node_id
of the authenticated each group registered for the organization associated with the authenticate user:
Code Block |
---|
{ "logindata": "octocat",{ "idviewer": 1,{ "avatar_url": "https://Scope.com/images/error/octocat_happy.gif", "gravatar_idlastName": "Support", "url": "https://api.Scope.com/users/octocat", "html_urlemail": "https://Scopesupport@scopear.com/octocat", "followers_url": "https://api.Scope.com/users/octocat/followers", "following_urlorganization": "https://api.Scope.com/users/octocat/following{/other_user}",{ "gists_urlgroups": "https://api.Scope.com/users/octocat/gists{/gist_id}",{ "starred_urlnodes": "https://api.Scope.com/users/octocat/starred{/owner}{/repo}", [ { "subscriptions_urlname": "https://api.Scope.com/users/octocat/subscriptions",Default", "organizations_url "id": "https://api.Scope.com/users/octocat/orgs",OiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY=", "repos_urldatabaseId": "https://api.Scope.com/users/octocat/repos", "events_url": "https://api.Scope.com/users/octocat/events{/privacy}", "received_events_url": "https://api.Scope.com/users/octocat/received_events", "type": "User", "site_admin": false,1" }, { "name": "GroupA", "id": "6_kJ_XUGDxMDWkwq2bAK-dKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX", "databaseId": "497" }, { "name": "monalisa octocatGroupB", "company "id": "Scope883xpQFv8XQ8-_RgxNUOHdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX", "blogdatabaseId": "https://Scope.com/blog",498" "location": "San Francisco", "email": "octocat@Scope.com", "hireable": false}, "bio": "There once was...", "public_repos": 2, { "public_gists": 1, "followers": 20, "following": 0, "created_atname": "2008-01-14T04:33:35ZGroupC", "updated_at "id": "2008-01-14T04:33:35Zp8jFJG8yW_IEBdf0IRiqRdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX", "private_gists "databaseId": 81,"593" "total_private_repos": 100, "owned_private_repos": 100, "disk_usage": 10000, }, "collaborators": 8, "two_factor_authentication": true, "plan": { "name": "MediumRAR Users", "space": 400, "private_reposid": 20"5s5FE2crVGovEVQX2rXEMdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX", "collaborators": 0 }, "node_iddatabaseId": "MDQ6VXNlcjU4MzIzMQ==" } 647" } ] } } } } } |
2. Find the object type in GraphQL
In this example, the node_id
value of the first group is MDQ6VXNlcjU4MzIzMQOiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY==
. You can use this value to query the same object in GraphQL.
You'll need to know the object's type first, though. You If you don’t know the type of an object, you can check the type with a simple GraphQL query:
Code Block |
---|
query{ "data": { "node(id:"MDQ6VXNlcjU4MzIzMQ==")": { "__typename": "Group" } } } |
This type of query—that is, finding the node by ID—is known as a "direct node lookup."
When you run this query, you'll see that the __typename
is User
Group
.
3. Do a direct node lookup in GraphQL
Once you've confirmed the type, you can use an inline fragment to an inline fragment to access the object by its ID and return additional data. In this example, we define the fields on User
that we'd like to query:
Code Block |
---|
query { node(id:"MDQ6VXNlcjU4MzIzMQOiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY==") { ... on UserGroup { name loginpath } } } |
This type of query is the standard approach for looking up an object by its global node ID.
Using global node IDs in migrations
When building integrations that use either the REST API or the GraphQL API, it's best practice to persist the global node ID so you can easily reference objects across API versions. For more information on handling the transition between REST and GraphQL, see "Migrating from REST to GraphQL."