New guide: AI is in production. Is your governance?

Announcing Visual Copilot - Figma to production in half the time

Builder.io
Builder.io
Contact sales

New guide: AI is in production. Is your governance?

Announcing Visual Copilot - Figma to production in half the time

Define and organize the structure of content within your Builder Space. Use these operations to create and manage models and folders that determine how content is stored and grouped.

Retrieve one or more data models from your Builder Space. For more details on models in Builder, see Models Intro.

To get all models from your Builder Space, use the following query.

Query

const response = await adminSDK
  .query({
    models: {
      id: true,
      fields: true,
    },
  });

Response

{
  "data": {
    "models": [
      ...
    ]
  }
}

To get one model by ID from your Builder Space, use the following query replacing "your-model-id" with your model's unique ID.

Query

const response = await adminSDK
  .query({
    model: {
      id: 'your-model-id',
      arguments: {
        id: 'your-model-id'
      },
      properties: {
        id: true,
        name: true,
        fields: true
      }
    },
  });

Response

{
  "data": {
    "models": {
      "id": "MODEL-ID",
      "name": "headline",
      "kind": "component",
      "fields": [
        {
          name: "Headline",
          type: "text",
          required: true,
        }
      ]
    }
  }
}

Create a new model within your Builder Space.

When creating a new model, you must include a name and kind. The fields key must also be present and have a value that is an array.

Query

const result = await adminSDK
  .chain.mutation.addModel({
    body: {
      name: "headline",
      kind: "component",
      fields: [
        {
          name: "Headline",
          type: "text",
          required: true
        }
      ]
    }
  })
  .execute();

Response

{
  "data": {
    "addModel": {
      "id": "...",
      "name": "headline",
      "kind": "component",
      "fields": [
        {
          name: "Headline",
          type: "text",
          required: true,
        }
      ]
    }
  }
}

Update an existing model within your Builder Space.

To update a model by ID from your Builder Space, use the following query replacing "your-model-id" with your model's unique ID. With this query, you may update any fields within the model.

Query

const result = await adminSDK
  .chain.mutation.updateModel({
    body: {
      id: "your-model-id",
      data: {
        fields: [
          {
            name: "Headline",
            type: "text",
            required: true
          },
          {
            name: "Subheadline",
            type: "text",
            required: false
          }
        ]
      }
    }
  })
  .execute();

Response

{
  "data": {
    "updateModel": {
      "id": "MODEL-ID",
      "name": "headline",
      "fields": [
        {
          "name": "Headline",
          "type": "text",
          "required": true
        },
        {
          "name": "Subheadline",
          "type": "text",
          "required": false
        }
      ]
    }
  }
}

Delete an existing model within your Builder Space. This operation is not reversible.

To delete a model by ID from your Builder Space, use the following query replacing "your-model-id" with your model's unique ID.

Query

const result = await adminSDK
  .chain.mutation.deleteModel({
    id: "your-model-id"
  })
  .execute();

Response

{
  "data": {
    "deleteModel": null
  }
}

Folders are used within Builder to organize content entries. For more details, see Managing Content.

To get all folders and their content entries' IDs from your Builder Space, use the following query.

Query

const response = await adminSDK
  .query({
    getFolders: {
      id: true,
      name: true,
      description: true,
      entries: true
    }
  });

Response

{
  "data": {
    "getFolders": [
      {
        "id": "...",
        "name": "My Folder",
        "description": "...",
        "entries": [
          "...",
          "..."
        ]
      }
    ]
  }
}

To get one folder by ID from your Builder Space, use the following query replacing "your-folder-id" with your model's unique ID.

Query

const response = await adminSDK
  .query({
    getFolder: {
      arguments: {
        id: "your-folder-id"
      },
      properties: {
        name: true,
        entries: true
      }
    }
  });

Response

{
  "data": {
    "getFolder": {
      "id": "FOLDER-ID",
      "name": "My Folder",
      "description": "...",
      "entries": [
        "...",
        "..."
      ]
    }
  }
}

Continue to explore the Admin API documentation or use the GraphQL Explorer to try out these queries with your own Space and Organization. Then, visit the Admin API GraphQL Schema for more details on how to modify your queries.

Was this article helpful?