Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

You can get global node IDs of objects via the REST API and or webhooks, and then use them in GraphQL operations.

In this article

You can access most objects in Scope (users, groups, scenarios, etc.) using either the REST API or the GraphQL API. With a recent update, you can find the global node ID of many objects from within the REST API and use these IDs in your GraphQL operations, and vice versa.

Note: 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."

Putting global node IDs to use

You can follow three steps to use global node IDs effectively:

  1. Call a REST endpoint that returns an object's node_id, receive a webhook that supplies an id for an object, or execute a GraphQL query that returns the id for an object.

  2. Find the object's type in GraphQL.

  3. 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 id for an object

While Exploring the Graph, execute the following query

query {
  viewer {
	organization {
      groups {
        nodes {
          id
        }
      }
    }
  }
}

you'll get a response that includes the id of each group registered for the organization associated with the authenticate user:

{
  "data": {
    "viewer": {
      "lastName": "Support",
      "email": "support@scopear.com",
      "organization": {
        "groups": {
          "nodes": [
            {
              "name": "Default",
              "id": "OiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY=",
              "databaseId": "1"
            },
            {
              "name": "GroupA",
              "id": "6_kJ_XUGDxMDWkwq2bAK-dKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX",
              "databaseId": "497"
            },
            {
              "name": "GroupB",
              "id": "883xpQFv8XQ8-_RgxNUOHdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX",
              "databaseId": "498"
            },
            {
              "name": "GroupC",
              "id": "p8jFJG8yW_IEBdf0IRiqRdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX",
              "databaseId": "593"
            },
            {
              "name": "RAR Users",
              "id": "5s5FE2crVGovEVQX2rXEMdKknUQ7GPpsI2yfj691f9L2n6N4sAhdU4urWqNG1RVX",
              "databaseId": "647"
            }
          ]
        }
      }
    }
  }
}

2. Find the object type in GraphQL

In this example, the id value of the first group is OiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY=. You can use this value to query the same object in GraphQL.

You'll need to know the object's type first, though. If you don’t know the type of an object, you can check the type with a simple GraphQL query:

{
  "data": {
    "node": {
      "__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 Group.

3. Do a direct node lookup in GraphQL

Once you've confirmed the type, you can use 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:

query {
  node(id:"OiSSdfK1Su4gwG4zAi2InavDB9eRE9aOnGHYRMG5dqY=") {
   ... on Group {
      name
      path
    }
  }
}

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."

  • No labels